mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-15 23:22:53 +08:00
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.)
This commit is contained in:
parent
99e0aa3c64
commit
b06a8a2e0c
9
share/functions/fish_nth_token.fish
Normal file
9
share/functions/fish_nth_token.fish
Normal file
@ -0,0 +1,9 @@
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user