Closed neogeographica closed 3 years ago
Interesting development on item 1...
Testing the word splitting with this little completion function:
_testcomp()
{
echo
echo "COMP_WORDS:"
local COMP_WORDS_SIZE=${#COMP_WORDS[@]}
for WORD in "${COMP_WORDS[@]}"
do
echo $WORD
done
echo
}
complete -F _testcomp testcomp
On Linux with bash version 4.4.20(1)-release, if I type testcomp hi="ho ho" foo
and hit tab, I get:
COMP_WORDS:
testcomp
hi
="
ho
ho" foo
However on macOS with bash version 5.1.4(1)-release I get the much more sensible:
COMP_WORDS:
testcomp
hi
=
"ho ho"
foo
This may just be a bug fixed in bash, and another reason to recommend (if not outright require) a minimum bash version. Need to try updating my bash version on Linux.
edit: yep look like that was fixed in bash 5: "iiii. Fixed a problem with splitting double-quoted words for programmable completion when the double quote immediately follows another word delimiter."
Closing this; will open new issue for the filepath thing.
I need to re-investigate, but I think what is happening is that e.g. if you hit tab after
foo="bar" baz
, instead of CUR beingbaz
it ends up beingbar" baz
. (And the preceding word is="
.)It works if you hit tab after
"foo=bar" baz
, but that's annoying as you don't always need quotes in front of the option, in fact you very rarely do unless the value is a filepath with spaces in it. Also putting a quote beforefoo
prevents autocomplete from working when typing foo, although I guess I could massage that.Not sure what the fix is (or even why COMP_WORDS is getting split in that exact way to begin with.) Since I know placeholders are formed from a very limited set of characters I could try to re-glue/re-split COMP_WORDS if I see a case like this, but I'm dubious that I can be sure that I'm not seeing something from inside a placeholder value.
E.g. after
map=/home
use tabs here and there to help autocomplete the whole path.Problem is, there's no metadata to tell the system that a particular placeholder value is a filepath, and I don't know if trying to introduce that is the right thing to do.