fish-shell/share/completions/pushd.fish
Kurtis Rader bd18736ee5 Switch to bare vars in our math invocations
Using bare vars is more efficient because it makes the builtin `math`
expression cache more useful. That's because if you prefix each var with
a dollar-sign then the fish parser expands it before `math` is run.
Something like `math x + 1` can be cached since the expression is the
same each time it is run. But if you do `math $x + 1` and x==1 then you're
effectively executing `math 1 + 1`. And if x==2 the next time then you're
running `math 2 + 1`. Which makes the expression cache much less effective.
2017-08-24 12:38:10 -07:00

35 lines
1.1 KiB
Fish

function __fish_complete_pushd_plus
if count $dirstack > /dev/null
# print each member of the stack, replace $HOME with ~
for i in (seq (count $dirstack))
printf "+%s\t%s\n" $i "Rotate to "(string replace -r "^$HOME" "~" -- $dirstack[$i])
end
end
end
function __fish_complete_pushd_minus
if count $dirstack > /dev/null
# print each member of the stack, replace $HOME with ~
# Negative arguments are expected to start at "-0"
for i in (seq (count $dirstack) -1 1)
printf "%s\t%s\n" -(math i - 1) "Rotate to "(string replace -r "^$HOME" "~" -- $dirstack[(math -i)])
end
end
end
function __fish_complete_pushd_swap
if count $dirstack > /dev/null
# replace $HOME with ~
printf "\t%s\n" "Swap with "(string replace -r "^$HOME" "~" -- $dirstack[1])
end
end
# support pushd <dir>
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)'
complete -c pushd -a '(__fish_complete_pushd_minus)'