From 56c0c24b553db8ad4b75d430f8ddf0a9ea5389bf Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 11 Feb 2022 12:02:27 +0000 Subject: [PATCH] Do not disable completion along with pathname expansion The -f/--noglob shell option is documented simply as: "Disables pathname expansion." But after 'set -f' on an interactive shell, command completion and file name completion also stop working. This is because they internally use the pathname expansion mechanism. But it is not documented anywhere that 'set -f' disables completion; it's just a side effect of an implementation detail. Though ksh has always acted like this, I think it should change because it's not useful or expected behaviour. Other shells like bash, yash or zsh don't act like this. src/cmd/ksh93/sh/expand.c, src/cmd/ksh93/sh/macro.c: - Allow the SH_COMPLETE (command completion) or SH_FCOMPLETE (file name completion) state bit to override SH_NOGLOB in path_generate() and in sh_macexpand(). --- NEWS | 3 +++ src/cmd/ksh93/sh/expand.c | 2 +- src/cmd/ksh93/sh/macro.c | 2 +- src/cmd/ksh93/tests/pty.sh | 7 +++++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 6e718db0c..b0ee23497 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ Any uppercase BUG_* names are modernish shell bug IDs. 2022-02-11: +- On the interactive shell, tab/esc completion is no longer disabled as a side + effect of turning off pathname expansion with 'set -f' or 'set -o noglob'. + - Fixed a bug in which a >&- or <&- redirection could persist past a subshell in certain corner cases involving 'exec' or 'redirect'. diff --git a/src/cmd/ksh93/sh/expand.c b/src/cmd/ksh93/sh/expand.c index 6576aa7c0..fbb58976c 100644 --- a/src/cmd/ksh93/sh/expand.c +++ b/src/cmd/ksh93/sh/expand.c @@ -284,7 +284,7 @@ again: for(; ap; ap=apin) { apin = ap->argchn.ap; - if(!sh_isoption(SH_NOGLOB)) + if(!sh_isoption(SH_NOGLOB) || sh_isstate(SH_COMPLETE) || sh_isstate(SH_FCOMPLETE)) brace=path_expand(ap->argval,arghead); else { diff --git a/src/cmd/ksh93/sh/macro.c b/src/cmd/ksh93/sh/macro.c index 1875bf5a2..744269203 100644 --- a/src/cmd/ksh93/sh/macro.c +++ b/src/cmd/ksh93/sh/macro.c @@ -212,7 +212,7 @@ int sh_macexpand(register struct argnod *argp, struct argnod **arghead,int flag) mp->arith = ((flag&ARG_ARITH)!=0); mp->split = !(flag&ARG_ASSIGN); mp->assign = !mp->split; - mp->pattern = mp->split && !(flag&ARG_NOGLOB) && !sh_isoption(SH_NOGLOB); + mp->pattern = mp->split && !(flag&ARG_NOGLOB) && (!sh_isoption(SH_NOGLOB) || sh_isstate(SH_COMPLETE) || sh_isstate(SH_FCOMPLETE)); mp->arrayok = mp->arith || (flag&ARG_ARRAYOK); str = argp->argval; fcsopen(str); diff --git a/src/cmd/ksh93/tests/pty.sh b/src/cmd/ksh93/tests/pty.sh index 211d1c836..06f316bb1 100755 --- a/src/cmd/ksh93/tests/pty.sh +++ b/src/cmd/ksh93/tests/pty.sh @@ -952,13 +952,16 @@ w exit touch "$tmp/foo bar" ((SHOPT_VSH || SHOPT_ESH)) && tst $LINENO <