Skip to content

Commit

Permalink
choose the handler using the longest prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Jul 26, 2022
1 parent 02c2869 commit e3a29ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ additional documentation and more details are available in `man gplaces`. type `
## Statistic
Language|files|blank|comment|code
:-------|-------:|-------:|-------:|-------:
C|1|242|58|1119
C|1|244|58|1127
12 changes: 11 additions & 1 deletion gplaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,17 @@ static int get_terminal_width() {

/*============================================================================*/
static const char *find_mime_handler(const char *mime) {
const char *handler = set_var(&variables, mime, NULL);
Variable *var;
const char *handler = NULL;
size_t length, longest = 0;

LIST_FOREACH(var, &variables, next) {
if ((length = strlen(var->name)) > longest && !strncasecmp(mime, var->name, length)) {
longest = length;
handler = var->data;
}
}

if (!handler) fprintf(stderr, "no handler for `%s`\n", mime);
return handler;
}
Expand Down
8 changes: 3 additions & 5 deletions gplacesrc.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

# define default handlers
set https "xdg-open %u"
set image/jpeg "xdg-open %f"
set image/png "xdg-open %f"
set image/gif "xdg-open %f"
set image/svg+xml "xdg-open %f"
set audio/mpeg "xdg-open %f"
set image/ "xdg-open %f"
set audio/ "mpv %f"
set video/ "mpv %f"
set application/pdf "xdg-open %f"

# define some aliases
Expand Down

0 comments on commit e3a29ed

Please sign in to comment.