2006-02-08 09:20:05 +00:00
|
|
|
#
|
|
|
|
# Find files that complete $argv[1], has the suffix $argv[2], and
|
2015-07-23 06:22:27 +00:00
|
|
|
# output them as completions with the optional description $argv[3] Both
|
2007-01-30 15:26:31 +00:00
|
|
|
# $argv[1] and $argv[3] are optional, if only one is specified, it is
|
|
|
|
# assumed to be the argument to complete.
|
2006-02-08 09:20:05 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
function __fish_complete_suffix -d "Complete using files"
|
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
# Variable declarations
|
2007-01-30 15:26:31 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
set -l comp
|
|
|
|
set -l suff
|
|
|
|
set -l desc
|
|
|
|
set -l files
|
2007-01-30 15:26:31 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
switch (count $argv)
|
2007-01-30 15:26:31 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
case 1
|
|
|
|
set comp (commandline -ct)
|
|
|
|
set suff $argv
|
|
|
|
set desc ""
|
2007-01-30 15:26:31 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
case 2
|
|
|
|
set comp $argv[1]
|
|
|
|
set suff $argv[2]
|
|
|
|
set desc ""
|
2007-01-30 15:26:31 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
case 3
|
|
|
|
set comp $argv[1]
|
|
|
|
set suff $argv[2]
|
|
|
|
set desc $argv[3]
|
2007-01-30 15:26:31 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
2007-01-30 15:26:31 +00:00
|
|
|
|
2018-04-29 16:17:35 +00:00
|
|
|
# Strip leading ./ as it confuses the detection of base and suffix
|
|
|
|
# It is conditionally re-added below.
|
2018-05-20 17:30:07 +00:00
|
|
|
set -l base_temp (string replace -r '^\\./' '' -- $comp)
|
2006-02-08 09:20:05 +00:00
|
|
|
|
2018-05-20 17:30:07 +00:00
|
|
|
set base (string replace -r '\\.[^.]*$' '' -- $base_temp | string trim -c '\'"') # " make emacs syntax highlighting happy
|
2018-04-29 16:17:35 +00:00
|
|
|
# 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.
|
2018-05-20 17:30:07 +00:00
|
|
|
if string match -qr '^\\./' -- $comp
|
2018-05-20 05:38:17 +00:00
|
|
|
# Also do directory completion, since there might be files
|
|
|
|
# with the correct suffix in a subdirectory
|
|
|
|
eval "set files ./$base*{$suff,/}"
|
2018-04-29 16:17:35 +00:00
|
|
|
else
|
2018-05-20 05:38:17 +00:00
|
|
|
# Also do directory completion, since there might be files
|
|
|
|
# with the correct suffix in a subdirectory
|
|
|
|
eval "set files $base*{$suff,/}"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Another problem is that expanded paths are not matched, either.
|
|
|
|
# So an expression like $HOME/foo*.zip will expand to /home/rdahl/foo-bar.zip
|
|
|
|
# but that no longer matches the expression at the command line.
|
|
|
|
if string match -qr '[${}*~]' $comp
|
|
|
|
set -l expanded
|
|
|
|
eval "set expanded $comp"
|
2018-05-20 17:30:07 +00:00
|
|
|
# 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)
|
2018-04-29 16:17:35 +00:00
|
|
|
end
|
2006-02-08 09:20:05 +00:00
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
if test $files[1]
|
|
|
|
printf "%s\t$desc\n" $files
|
|
|
|
end
|
2006-02-08 09:20:05 +00:00
|
|
|
|
|
|
|
end
|