summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-10-30 12:28:07 +0000
committerPeter Stephenson <pws@zsh.org>2015-10-30 12:28:07 +0000
commit58f4cccb1fbd66b7645178af971cb317cf1a2d7a (patch)
tree14b088261d1970c9a68a1a6d7bdef5069f685f3c /Src
parentde9effbce601db7ad7f7f0d0969b70b920b4e371 (diff)
downloadzsh-58f4cccb1fbd66b7645178af971cb317cf1a2d7a.tar.gz
zsh-58f4cccb1fbd66b7645178af971cb317cf1a2d7a.zip
37022: add GLOB_STAR_SHORT option to abbreviate ** and ***
Diffstat (limited to 'Src')
-rw-r--r--Src/glob.c43
-rw-r--r--Src/options.c1
-rw-r--r--Src/zsh.h1
3 files changed, 27 insertions, 18 deletions
diff --git a/Src/glob.c b/Src/glob.c
index 24e60d0c5..51ffeb5d5 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -682,25 +682,32 @@ parsecomplist(char *instr)
char *str;
int compflags = gf_noglobdots ? (PAT_FILE|PAT_NOGLD) : PAT_FILE;
- if (instr[0] == Star && instr[1] == Star &&
- (instr[2] == '/' || (instr[2] == Star && instr[3] == '/'))) {
- /* Match any number of directories. */
- int follow;
-
- /* with three stars, follow symbolic links */
- follow = (instr[2] == Star);
- instr += (3 + follow);
-
- /* Now get the next path component if there is one. */
- l1 = (Complist) zhalloc(sizeof *l1);
- if ((l1->next = parsecomplist(instr)) == NULL) {
- errflag |= ERRFLAG_ERROR;
- return NULL;
+ if (instr[0] == Star && instr[1] == Star) {
+ int shortglob = 0;
+ if (instr[2] == '/' || (instr[2] == Star && instr[3] == '/')
+ || (shortglob = isset(GLOBSTARSHORT))) {
+ /* Match any number of directories. */
+ int follow;
+
+ /* with three stars, follow symbolic links */
+ follow = (instr[2] == Star);
+ /*
+ * With GLOBSTARSHORT, leave a star in place for the
+ * pattern inside the directory.
+ */
+ instr += ((shortglob ? 1 : 3) + follow);
+
+ /* Now get the next path component if there is one. */
+ l1 = (Complist) zhalloc(sizeof *l1);
+ if ((l1->next = parsecomplist(instr)) == NULL) {
+ errflag |= ERRFLAG_ERROR;
+ return NULL;
+ }
+ l1->pat = patcompile(NULL, compflags | PAT_ANY, NULL);
+ l1->closure = 1; /* ...zero or more times. */
+ l1->follow = follow;
+ return l1;
}
- l1->pat = patcompile(NULL, compflags | PAT_ANY, NULL);
- l1->closure = 1; /* ...zero or more times. */
- l1->follow = follow;
- return l1;
}
/* Parse repeated directories such as (dir/)# and (dir/)## */
diff --git a/Src/options.c b/Src/options.c
index 1fb102f1d..3bf9f39a4 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -140,6 +140,7 @@ static struct optname optns[] = {
{{NULL, "globassign", OPT_EMULATE|OPT_CSH}, GLOBASSIGN},
{{NULL, "globcomplete", 0}, GLOBCOMPLETE},
{{NULL, "globdots", OPT_EMULATE}, GLOBDOTS},
+{{NULL, "globstarshort", OPT_EMULATE}, GLOBSTARSHORT},
{{NULL, "globsubst", OPT_EMULATE|OPT_NONZSH}, GLOBSUBST},
{{NULL, "hashcmds", OPT_ALL}, HASHCMDS},
{{NULL, "hashdirs", OPT_ALL}, HASHDIRS},
diff --git a/Src/zsh.h b/Src/zsh.h
index d03d171e4..a6f039741 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2215,6 +2215,7 @@ enum {
GLOBASSIGN,
GLOBCOMPLETE,
GLOBDOTS,
+ GLOBSTARSHORT,
GLOBSUBST,
HASHCMDS,
HASHDIRS,