2006-02-08 19:20:05 +10:00
|
|
|
#
|
|
|
|
# Find directories that complete $argv[1], output them as completions
|
2018-05-12 14:04:49 -05:00
|
|
|
# with description $argv[2] if defined, otherwise use 'Directory'.
|
|
|
|
# If no arguments are provided, attempts to complete current commandline token.
|
2006-02-08 19:20:05 +10:00
|
|
|
#
|
2020-09-19 11:39:51 +02:00
|
|
|
function __fish_complete_directories -d "Complete directory prefixes" --argument-names comp desc
|
2017-04-10 20:40:25 -07:00
|
|
|
if not set -q desc[1]
|
2020-03-09 19:36:12 +01:00
|
|
|
set desc Directory
|
2016-11-27 21:27:22 -08:00
|
|
|
end
|
2006-02-08 19:20:05 +10:00
|
|
|
|
2018-05-12 14:04:49 -05:00
|
|
|
if not set -q comp[1]
|
|
|
|
set comp (commandline -ct)
|
|
|
|
end
|
|
|
|
|
2019-05-27 19:33:52 +02:00
|
|
|
# HACK: We call into the file completions by using a non-existent command.
|
|
|
|
# If we used e.g. `ls`, we'd run the risk of completing its options or another kind of argument.
|
|
|
|
# But since we default to file completions, if something doesn't have another completion...
|
|
|
|
set -l dirs (complete -C"nonexistentcommandooheehoohaahaahdingdongwallawallabingbang $comp" | string match -r '.*/$')
|
2018-05-20 12:30:07 -05:00
|
|
|
|
2017-04-10 20:40:25 -07:00
|
|
|
if set -q dirs[1]
|
2016-11-27 21:27:22 -08:00
|
|
|
printf "%s\t$desc\n" $dirs
|
|
|
|
end
|
2006-02-08 19:20:05 +10:00
|
|
|
end
|