2006-02-08 17:20:05 +08:00
|
|
|
#
|
|
|
|
# Find files that complete $argv[1], has the suffix $argv[2], and
|
2015-07-23 14:22:27 +08:00
|
|
|
# output them as completions with the optional description $argv[3] Both
|
2007-01-30 23:26:31 +08: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 17:20:05 +08:00
|
|
|
#
|
|
|
|
|
|
|
|
function __fish_complete_suffix -d "Complete using files"
|
|
|
|
|
2007-01-30 23:26:31 +08:00
|
|
|
# Variable declarations
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
set -l comp
|
|
|
|
set -l suff
|
|
|
|
set -l desc
|
2007-01-30 23:26:31 +08:00
|
|
|
set -l files
|
|
|
|
|
|
|
|
switch (count $argv)
|
|
|
|
|
|
|
|
case 1
|
|
|
|
set comp (commandline -ct)
|
|
|
|
set suff $argv
|
2015-07-23 14:22:27 +08:00
|
|
|
set desc ""
|
2007-01-30 23:26:31 +08:00
|
|
|
|
|
|
|
case 2
|
|
|
|
set comp $argv[1]
|
|
|
|
set suff $argv[2]
|
2015-07-23 14:22:27 +08:00
|
|
|
set desc ""
|
2007-01-30 23:26:31 +08:00
|
|
|
|
2011-09-23 16:24:21 +08:00
|
|
|
case 3
|
2007-01-30 23:26:31 +08:00
|
|
|
set comp $argv[1]
|
|
|
|
set suff $argv[2]
|
2011-09-23 16:24:21 +08:00
|
|
|
set desc $argv[3]
|
2007-01-30 23:26:31 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# Perform the completion
|
2006-02-08 17:20:05 +08:00
|
|
|
|
2006-12-13 04:37:27 +08:00
|
|
|
set base (echo $comp |sed -e 's/\.[a-zA-Z0-9]*$//')
|
|
|
|
eval "set files $base*$suff"
|
2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
if test $files[1]
|
|
|
|
printf "%s\t$desc\n" $files
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Also do directory completion, since there might be files
|
|
|
|
# with the correct suffix in a subdirectory
|
2015-07-23 14:22:27 +08:00
|
|
|
# No need to describe directories (#279)
|
2006-02-08 17:20:05 +08:00
|
|
|
#
|
|
|
|
|
2015-07-23 14:22:27 +08:00
|
|
|
__fish_complete_directories $comp ""
|
2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
end
|