mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 13:23:09 +00:00
6dc74d3b6c
For usage in completion scripts. Unlike `__fish_is_first_token` (which is probably not correctly named), `__fish_is_first_arg` returns true regardless of whether existing tokens start with `-` or not, to be used when an arg cannot be used with any other argument. `__fish_prev_arg_in` is similar to `__fish_seen_...` but it explicitly tests the preceding token only, for arguments that take only a single parameter.
16 lines
347 B
Fish
16 lines
347 B
Fish
# returns 0 only if previous argument is one of the supplied arguments
|
|
function __fish_prev_arg_in
|
|
set -l tokens (commandline -co)
|
|
set -l tokenCount (count $tokens)
|
|
if test $tokenCount -lt 2
|
|
# need at least cmd and prev argument
|
|
return 1
|
|
end
|
|
for arg in $argv
|
|
if string match -q -- $tokens[-1] $arg
|
|
return 0
|
|
end
|
|
end
|
|
|
|
return 1
|
|
end
|