fish-shell/share/functions/__fish_can_complete_switches.fish
Mahmoud Al-Qudsi 7db0958804 Add __fish_can_complete_switches & __fish_should_complete_switches
To be used by completions to directly determine whether it is either
possible or preferable to complete a switch (instead of a subcommand),
(presuming that switches must come before subcommands).

* __fish_can_complete_switches: we are in a position where a switch may
be placed.
* __fish_should_complete_switches: we're in a position to accept a
switch and the current token starts with `-` so we have no choice but
to do so.
2018-04-19 18:09:10 -05:00

15 lines
323 B
Fish

# Returns whether it is at all possible (even if not recommended)
# to complete a -s or --long argument.
function __fish_can_complete_switches
# Search backwards
for arg in (commandline -ct)[-1..1]
if test "$arg" = ""
continue
else if not string match -qr -- "^-\S*\$" "$arg"
return 1
end
end
return 0
end