mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Turns out there is a bona fide, honest-to-goodness use case for matching '.' and '..' in globbing after all. It's when globbing is used as the backend mechanism for file name completion in interactive shell editors. A tab invisibly adds a * at the end of the word to the left of your cursor and the resulting pattern is expanded. In5312a59d, this broke for '.' and '..'. Typing '.' followed by two tabs should result in a menu that includes './' and '../'. Typing '..' followed by a tab should result in '../', (or a menu that includes it if there are files with names starting with '..'). This is the behaviour in 93u+ and we should maintain this. To restore this functionality without reintroducing the harmful behaviour fixed in the referenced commits, we should special-case this, allowing '.' and '..' to match only for file name completion. src/lib/libast/include/glob.h: - Fix an inaccurate comment: the GLOB_COMPLETE flag is used for command completion, not file name completion. This is very clear from reading the path_expand() function in sh/expand.c. - Add new GLOB_FCOMPLETE flag for file name completion. src/lib/libast/misc/glob.c: - Adapt flags mask to fit the new flag. - glob_dir(): If GLOB_FCOMPLETE is passed, allow '.' and '..' to match even if expanded from a pattern. - Clarify the fix fromaad74597with an extended comment based on <https://github.com/ksh93/ksh/issues/146#issuecomment-790991990>. src/cmd/ksh93/sh/expand.c: path_expand(): - If we're in the SH_FCOMPLETE (file name completion) state, then pass the new GLOB_FCOMPLETE flag to AST glob(3). Fixes: https://github.com/ksh93/ksh/issues/372 Thanks to @fbrau for the bug report.
This commit is contained in:
parent
e54001d58b
commit
fc752b574a
6 changed files with 42 additions and 6 deletions
|
|
@ -113,7 +113,7 @@ struct _glob_
|
|||
#define GLOB_STARSTAR 0x0080 /* enable [/]**[/] expansion */
|
||||
#define GLOB_BRACE 0x0100 /* enable {...} expansion */
|
||||
#define GLOB_ICASE 0x0200 /* ignore case on match */
|
||||
#define GLOB_COMPLETE 0x0400 /* shell file completion */
|
||||
#define GLOB_COMPLETE 0x0400 /* shell command completion */
|
||||
#define GLOB_AUGMENTED 0x0800 /* augmented shell patterns */
|
||||
#define GLOB_STACK 0x1000 /* allocate on current stack */
|
||||
#define GLOB_LIST 0x2000 /* just create gl_list */
|
||||
|
|
@ -121,6 +121,7 @@ struct _glob_
|
|||
#define GLOB_DISC 0x8000 /* discipline initialized */
|
||||
#define GLOB_GROUP 0x10000 /* REG_SHELL_GROUP */
|
||||
#define GLOB_DCASE 0x20000 /* detect FS case insensitivity */
|
||||
#define GLOB_FCOMPLETE 0x40000 /* shell file name completion */
|
||||
|
||||
/* gl_status */
|
||||
#define GLOB_NOTDIR 0x0001 /* last gl_dirnext() not a dir */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue