mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
b06a8a2e0c
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.)
9 lines
384 B
Fish
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
|