Support expansions in directory completions as well

Also fixes some issues with duplicate results in __fish_complete_suffix.
This commit is contained in:
Mahmoud Al-Qudsi 2018-05-20 12:30:07 -05:00
parent 5bd121bd6d
commit beac145e75
3 changed files with 13 additions and 5 deletions

View file

@ -57,6 +57,7 @@ This section is for changes merged to the `major` branch that are not also merge
- Variables set in `if` and `while` conditions are available outside the block (#4820).
- The universal variables file no longer contains the MAC address. It is now at the fixed location `.config/fish/fish_universal_variables` (#1912).
- `alias` now has a `-s` and `--save` option to save the function generated by the alias using `funcsave` (#4878).
- Path completions now support expansions, meaning expressions like `python ~/<TAB>` now provides file suggestions just like any other relative or absolute path. (This includes support for other expansions, too.)
## Other significant changes
- Command substitution output is now limited to 10 MB by default (#3822).

View file

@ -12,7 +12,10 @@ function __fish_complete_directories -d "Complete directory prefixes" --argument
set comp (commandline -ct)
end
set -l dirs $comp*/
# Inherit support for completing expansions from __fish_complete_suffix
# Supports completing expressions like ~/foo or x$bar, etc.
set -l dirs (__fish_complete_suffix $comp /)
if set -q dirs[1]
printf "%s\t$desc\n" $dirs
end

View file

@ -35,16 +35,16 @@ function __fish_complete_suffix -d "Complete using files"
# Strip leading ./ as it confuses the detection of base and suffix
# It is conditionally re-added below.
set -l base_temp (string replace -r '^\./' '' -- $comp)
set -l base_temp (string replace -r '^\\./' '' -- $comp)
set base (string replace -r '\.[^.]*$' '' -- $base_temp | string trim -c '\'"') # " make emacs syntax highlighting happy
set base (string replace -r '\\.[^.]*$' '' -- $base_temp | string trim -c '\'"') # " make emacs syntax highlighting happy
# echo "base: $base" > /dev/tty
# echo "suffix: $suff" > /dev/tty
# If $comp is "./ma" and the file is "main.py", we'll catch that case here,
# but complete.cpp will not consider it a match, so we have to output the
# correct form.
if string match -qr '^\./' -- $comp
if string match -qr '^\\./' -- $comp
# Also do directory completion, since there might be files
# with the correct suffix in a subdirectory
eval "set files ./$base*{$suff,/}"
@ -60,7 +60,11 @@ function __fish_complete_suffix -d "Complete using files"
if string match -qr '[${}*~]' $comp
set -l expanded
eval "set expanded $comp"
set files (string replace -- $expanded $comp $files)
# It's very unfortunate to do all this work in-process and have to shell out here,
# but unfortunately at this time expressions like "foo{t,te}*" applied against
# "footer" will result in "footer" being reported twice. Not sure if this can be
# term a "bug" per-se.
set files (string replace -- $expanded $comp $files | sort -u)
end
if test $files[1]