mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-14 00:47:30 +00:00
4a3e55f69c
A completion entry like «complete -a '\\~'» results in completions that insert \~ into the command line. However we usually want to insert ~, but there is no way to do that. There are a couple of longstanding issues about completion escaping [1]. Until we fix those in a general way, fix the common case by never escaping tildes when applying custom completions to the command line. This is a hack but will probably work out fine because we don't expect literal tildes in arguments. The tilde is included in completions for cdh, or __fish_complete_suffix, which simply forwards results from "complete -C". Revert a workaround to cdh that expanded ~, because we can now render that without escaping. Closes #4570, #8441 [ja: tweak patch and commit message] [1]: https://github.com/fish-shell/fish-shell/pull/8441#discussion_r748803338
23 lines
754 B
Fish
23 lines
754 B
Fish
function __fish_cdh_args
|
|
set -l all_dirs $dirprev $dirnext
|
|
set -l uniq_dirs
|
|
|
|
# This next bit of code doesn't do anything useful at the moment since the fish pager always
|
|
# sorts, and eliminates duplicate, entries. But we do this to mimic the modal behavor of `cdh`
|
|
# and in hope that the fish pager behavior will be changed to preserve the order of entries.
|
|
for dir in $all_dirs[-1..1]
|
|
if not contains $dir $uniq_dirs
|
|
set uniq_dirs $uniq_dirs $dir
|
|
end
|
|
end
|
|
|
|
for dir in $uniq_dirs
|
|
set -l home_dir (string match -r "$HOME(/.*|\$)" "$dir")
|
|
if set -q home_dir[2]
|
|
set dir "~$home_dir[2]"
|
|
end
|
|
echo $dir
|
|
end
|
|
end
|
|
|
|
complete -c cdh -kxa '(__fish_cdh_args)'
|