fish-shell/share/functions/fish_nth_token.fish
Mahmoud Al-Qudsi b06a8a2e0c Add public function fish_nth_token to mirror fish_is_nth_token
Completions may benefit from using these in tandem to dynamically generate
completions predicated on the value of an earlier token in a cleaner fashion.
(Currently, most of called completion helper functions introspect the command
line to get the value of an earlier argument, making them less reusable for
different expressions that need completions of the same type. This way, the
completion can provide the function with the argument value explicitly.)
2022-02-08 14:17:00 -06:00

9 lines
384 B
Fish

function fish_nth_token --description 'Prints the Nth token (ignoring command and switches/flags)' --argument-names n
set -l tokens (commandline -po | string replace -r --filter '^([^-].*)' '$1')
# Increment $n by one to account for ignoring the command
if test (count $tokens) -ge (math "$n" + 1)
echo $tokens[(math $n + 1)]
else
return 1
end
end