diff --git a/share/functions/fish_nth_token.fish b/share/functions/fish_nth_token.fish new file mode 100644 index 000000000..7df863ae6 --- /dev/null +++ b/share/functions/fish_nth_token.fish @@ -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