fix(_umount,feh,sbopkg): check diretory name for _comp_compgen -C#1297
fix(_umount,feh,sbopkg): check diretory name for _comp_compgen -C#1297akinomyoga merged 2 commits intoscop:mainfrom
_comp_compgen -C#1297Conversation
In the current master, an error message is printed on the TAB completion with the following command line (where the cursor position is placed before the marker "[TAB]"): $ set -u $ feh --font x[TAB] --fontpath bash: words[i + 1]: unbound variable
* fix(_umount): specify the correct path as a directory * fix(feh): check the directory name before attempting path completion * fix(sbopkg): check the QUEUEDIR value before generating *.sqf
| -f -X "!*.@([tT][tT][fF])" -S / | ||
| if [[ -d $font_path ]]; then | ||
| _comp_compgen -aC "$font_path" -- \ | ||
| -f -X "!*.@([tT][tT][fF])" -S / |
There was a problem hiding this comment.
Unrelated to the present topic, but I'm wondering about the reasoning for using -f -X "!globpat" instead of simply -G "globpat". In the codebase, we only have two uses of -G globpat:
./completions/mdtool:35: _comp_compgen -- -o filenames -G"*.mds"
./completions/rcs:24: _comp_compgen -aR -- -G "$dir/$file*,v"
while we have many for -f -X "!globpat":
./completions/explodepkg:3:complete -o plusdirs -f -X '!*.t[bglx]z' explodepkg
./completions/feh:32: # _comp_compgen -C "$font_path" -- -f -X "!*.@([tT][tT][fF])" -S /
./completions/feh:38: -f -X "!*.@([tT][tT][fF])" -S /
./completions/gdb:41: _comp_compgen -a -- -f -X '!?(*/)core?(.?*)' -o plusdirs
./completions/java:87: _comp_compgen -av tmp -c "$i/$cur" -- -f -X '!*.class'
./completions/lzip:47: _comp_compgen -- -f -X "*.lz" -o plusdirs
./completions/sbopkg:67: _comp_compgen -aC "$QUEUEDIR" -- -f -X "!*.sqf"
./completions/_slackpkg:68: _comp_compgen -C "$confdir/templates" -- -f -X \
"!?*.template" && COMPREPLY=("${COMPREPLY[@]%.template}")
./completions/upgradepkg:18: _comp_compgen -- -P "$prev%" -f -X "!*.@(t[bgxl]z)" || nofiles=setedit: One possibile explanation is that they derived from the pattern -f -X "$_xspec" used in _comp_compgen_filedir. In that case, we can probably use -G.
edit: I also checked the history of the support for -G by the compgen builtin, but the option -G seems to have existed from the beginning when compgen was introduced in Bash 2.04 (1999).
There was a problem hiding this comment.
I also think the following @(...) are not needed (where ... does not contain |):
./completions/feh:32: # _comp_compgen -C "$font_path" -- -f -X "!*.@([tT][tT][fF])" -S /
./completions/feh:38: -f -X "!*.@([tT][tT][fF])" -S /
./completions/upgradepkg:18: _comp_compgen -- -P "$prev%" -f -X "!*.@(t[bgxl]z)" || nofiles=set
./completions/valgrind:10: if [[ ${words[i]} != @([-=])* ]]; thenThere was a problem hiding this comment.
I also think the following
@(...)are not needed (where...does not contain|):./completions/feh:32: # _comp_compgen -C "$font_path" -- -f -X "!*.@([tT][tT][fF])" -S / ./completions/feh:38: -f -X "!*.@([tT][tT][fF])" -S / ./completions/upgradepkg:18: _comp_compgen -- -P "$prev%" -f -X "!*.@(t[bgxl]z)" || nofiles=set ./completions/valgrind:10: if [[ ${words[i]} != @([-=])* ]]; then
Yeah, it would be nicer like that
About -f -X vs -G, I don't really have a strong opinion, but seems fine to change where possible to -G (note the lzip example you showed doesn't have a !)
There was a problem hiding this comment.
Thank you! I'll submit the fixes later.
There was a problem hiding this comment.
As for -f -X '!pat' vs -G 'pat', there does seem to be a difference. Although they are consistent when it generates the filename in the current directory:
$ compgen -G '*.md'
CHANGELOG.md
CONTRIBUTING.md
README.md
style.md
$ compgen -f -X '!*.md'
README.md
CONTRIBUTING.md
CHANGELOG.md
style.mdthey produce different results when they are used to generate completions in a subdirectory:
$ compgen -G '*.md' -- doc/
CHANGELOG.md
CONTRIBUTING.md
README.md
style.md
$ compgen -f -X '!*.md' -- doc/
doc/api-and-naming.md
doc/styleguide.md
doc/testing.md
doc/configuration.md(This hidden part was my misunderstanding)
We may still write it as
$ cur=doc/
$ compgen -G '*.md' -P "${cur%%+([^/])}" -- "$cur"
doc/CHANGELOG.md
doc/CONTRIBUTING.md
doc/README.md
doc/style.mdbut it is even more non-trivial than -f -X '!pat'.
edit: The -G option only generates the filenames in the current directory even when we try to generate the filenames in a subdirectory. In addition, the filtering by cur does not seem to be applied to the completions generated by -X.
_comp_compgen -C
scop#1297 (comment) The compgen option `-X '!pat'` has a problem that it only generates the filenames in the current directory and that it does not perform the filtering by the "cur" specified to the argument of `compgen`: $ compgen -G '*.md' -- doc/ CHANGELOG.md CONTRIBUTING.md README.md style.md In this patch, we use `-f -X '!pat'`, which does not have those limitations.
scop#1297 (comment) The compgen option `-X '!pat'` has a problem that it only generates the filenames in the current directory and that it does not perform the filtering by the "cur" specified to the argument of `compgen`: $ compgen -G '*.md' -- doc/ CHANGELOG.md CONTRIBUTING.md README.md style.md In this patch, we use `-f -X '!pat'`, which does not have those limitations.
scop#1297 (comment) The compgen option `-X '!pat'` has a problem that it only generates the filenames in the current directory and that it does not perform the filtering by the "cur" specified to the argument of `compgen`: $ compgen -G '*.md' -- doc/ CHANGELOG.md CONTRIBUTING.md README.md style.md In this patch, we use `-f -X '!pat'`, which does not have those limitations.
scop#1297 (comment) The compgen option `-X '!pat'` has a problem that it only generates the filenames in the current directory and that it does not perform the filtering by the "cur" specified to the argument of `compgen`: $ compgen -G '*.md' -- doc/ CHANGELOG.md CONTRIBUTING.md README.md style.md In this patch, we use `-f -X '!pat'`, which does not have those limitations.
Fixes #1260
This is an alternative fix to #1290. The fix suggested in #1290 was just to remove the error message, which I believe is not the right fix. This PR fixes it by checking the arguments at the caller side.
This includes an additional fix e9e665e for
feh. In the currentmainbranch, an error message is printed on the TAB completion with the following command line: