2006-02-08 09:20:05 +00:00
|
|
|
#
|
|
|
|
# Find directories that complete $argv[1], output them as completions
|
2018-05-12 19:04:49 +00:00
|
|
|
# with description $argv[2] if defined, otherwise use 'Directory'.
|
|
|
|
# If no arguments are provided, attempts to complete current commandline token.
|
2006-02-08 09:20:05 +00:00
|
|
|
#
|
2020-09-19 09:39:51 +00:00
|
|
|
function __fish_complete_directories -d "Complete directory prefixes" --argument-names comp desc
|
2017-04-11 03:40:25 +00:00
|
|
|
if not set -q desc[1]
|
2020-03-09 18:36:12 +00:00
|
|
|
set desc Directory
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
2006-02-08 09:20:05 +00:00
|
|
|
|
2018-05-12 19:04:49 +00:00
|
|
|
if not set -q comp[1]
|
2023-03-27 20:55:45 +00:00
|
|
|
# No token given, so we use the current commandline token.
|
|
|
|
# If we have a --name=val option, we need to remove it,
|
|
|
|
# or the complete -C below would keep it, and then whatever complete
|
|
|
|
# called us would add it again (assuming it's in the current token)
|
|
|
|
set comp (commandline -ct | string replace -r -- '^-[^=]*=' '' $comp)
|
2018-05-12 19:04:49 +00:00
|
|
|
end
|
|
|
|
|
2023-02-14 16:06:11 +00:00
|
|
|
# HACK: We call into the file completions by using an empty command
|
2019-05-27 17:33:52 +00:00
|
|
|
# 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...
|
2023-02-14 16:06:11 +00:00
|
|
|
# (really this should have an actual complete option)
|
|
|
|
set -l dirs (complete -C"'' $comp" | string match -r '.*/$')
|
2018-05-20 17:30:07 +00:00
|
|
|
|
2017-04-11 03:40:25 +00:00
|
|
|
if set -q dirs[1]
|
2023-02-14 16:06:11 +00:00
|
|
|
printf "%s\n" $dirs\t"$desc"
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
2006-02-08 09:20:05 +00:00
|
|
|
end
|