From e75108fc4cfc5f0a4ec5361f0194ddb21a9468c1 Mon Sep 17 00:00:00 2001 From: Derek Harland Date: Sat, 26 Sep 2015 14:39:01 +1200 Subject: [PATCH] Improve pushd completions Add completions for rotating and swapping the stack. --- share/completions/pushd.fish | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/share/completions/pushd.fish b/share/completions/pushd.fish index 49958bf89..9c64c5f18 100644 --- a/share/completions/pushd.fish +++ b/share/completions/pushd.fish @@ -1 +1,28 @@ -complete -c pushd -x -a "(__fish_complete_cd)" +function __fish_complete_pushd_plus + if count $dirstack > /dev/null + # TODO: Shift to using string replace when released + # + # print each member of the stack, replace $HOME with ~ + for i in (seq (count $dirstack)) + echo +$i\tRotate to (echo $dirstack[$i] | sed -e "s|^$HOME|~|") + end + end +end + +function __fish_complete_pushd_swap + if count $dirstack > /dev/null + # TODO: Shift to using string replace when released + # + # replace $HOME with ~ + echo ''\tSwap with (echo $dirstack[1] | sed -e "s|^$HOME|~|") + end +end + +# support pushd +complete -c pushd -a "(__fish_complete_cd)" + +# support pushd <> +complete -c pushd -a '(__fish_complete_pushd_swap)' + +# support pushd <+n> +complete -c pushd -a '(__fish_complete_pushd_plus)'