diff options
-rw-r--r-- | xe.1 | 1 | ||||
-rw-r--r-- | xe.c | 24 |
2 files changed, 23 insertions, 2 deletions
diff --git a/xe.1 b/xe.1 index b75209d..449879c 100644 --- a/xe.1 +++ b/xe.1 @@ -144,6 +144,7 @@ and replaces the first occurrence of .Li Sq \&% with the matched string in the remaining arguments, which are then used as the command to be executed. +Patterns without a slash are matched against the basenames only. .Pp Multiple runs of patterns and commands are separated by .Li Sq \&+ . diff --git a/xe.c b/xe.c index 1888775..19c1a26 100644 --- a/xe.c +++ b/xe.c @@ -362,6 +362,12 @@ parse_jobs(char *s) int perc_match(char *pat, char *arg) { + if (!strchr(pat, '/')) { + char *d = strrchr(arg, '/'); + if (d) + arg = d + 1; + } + char *s = strchr(pat, '%'); if (!s) @@ -382,6 +388,14 @@ perc_subst(char *pat, char *base, char *arg) { static char buf[2048]; size_t l; + char *dir = base; + + if (!strchr(pat, '/')) { + char *d = strrchr(base, '/'); + if (d) + base = d + 1; + } + char *s = strchr(pat, '%'); char *t = strchr(arg, '%'); @@ -389,7 +403,10 @@ perc_subst(char *pat, char *base, char *arg) return arg; if (s) - l = snprintf(buf, sizeof buf, "%.*s%.*s%.*s", + l = snprintf(buf, sizeof buf, "%.*s%.*s%.*s%.*s", + (int)(base - dir), + dir, + (int)(t - arg), arg, @@ -399,7 +416,10 @@ perc_subst(char *pat, char *base, char *arg) (int)(arg + strlen(arg) - t), t+1); else - l = snprintf(buf, sizeof buf, "%.*s%s%.*s", + l = snprintf(buf, sizeof buf, "%.*s%.*s%s%.*s", + (int)(base - dir), + dir, + (int)(t - arg), arg, |