mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-07 18:21:16 -03:00
Migrate PATH-completion logic from complete.cpp to expand.cpp
Prior to this fix, when completing a command that doesn't have a /, we would prepend each component of PATH and then expand the whole thing. So any special characters in the PATH would be interpreted when performing tab completion. With this fix, we pull the PATH resolution out of complete.cpp and migrate it to expand.cpp. This unifies nicely with the CDPATH resolution already in that file. This requires introducing a new expand flag EXPAND_SPECIAL_FOR_COMMAND, which is analogous to EXPAND_SPECIAL_CD (which is renamed to EXPAND_SPECIAL_FOR_CD). This flag tells expand to resolve paths against PATH instead of the working directory. Fixes #952
This commit is contained in:
committed by
Kurtis Rader
parent
36691df6fe
commit
e395a0eb69
@@ -72,3 +72,37 @@ if begin; rm -rf test6.tmp.dir; and mkdir test6.tmp.dir; end
|
||||
else
|
||||
echo "error: could not create temp environment" >&2
|
||||
end
|
||||
|
||||
# Test command expansion with parened PATHs (#952)
|
||||
begin
|
||||
set -l parened_path $PWD/'test6.tmp2.(paren).dir'
|
||||
set -l parened_subpath $parened_path/subdir
|
||||
if not begin
|
||||
rm -rf $parened_path
|
||||
and mkdir $parened_path
|
||||
and mkdir $parened_subpath
|
||||
and ln -s /bin/ls $parened_path/'__test6_(paren)_command'
|
||||
and ln -s /bin/ls $parened_subpath/'__test6_subdir_(paren)_command'
|
||||
end
|
||||
echo "error: could not create command expansion temp environment" >&2
|
||||
end
|
||||
|
||||
# Verify that we can expand commands when PATH has parens
|
||||
set -l PATH $parened_path $PATH
|
||||
set -l completed (complete -C__test6_ | cut -f 1 -d \t)
|
||||
if test "$completed" = '__test6_(paren)_command'
|
||||
echo "Command completion with parened PATHs test passed"
|
||||
else
|
||||
echo "Command completion with parened PATHs test failed. Expected __test6_(paren)_command, got $completed" >&2
|
||||
end
|
||||
|
||||
# Verify that commands with intermediate slashes do NOT expand with respect to PATH
|
||||
set -l completed (complete -Csubdir/__test6_subdir)
|
||||
if test -z "$completed"
|
||||
echo "Command completion with intermediate slashes passed"
|
||||
else
|
||||
echo "Command completion with intermediate slashes: should output nothing, instead got $completed" >&2
|
||||
end
|
||||
|
||||
rm -rf $parened_path
|
||||
end
|
||||
|
||||
@@ -33,3 +33,5 @@ CCCC:
|
||||
implicit cd complete works
|
||||
no implicit cd complete after 'command'
|
||||
PATH does not cause incorrect implicit cd
|
||||
Command completion with parened PATHs test passed
|
||||
Command completion with intermediate slashes passed
|
||||
|
||||
Reference in New Issue
Block a user