mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-11 22:21:14 -03:00
Replaced all uses of argparse -i with argparse -u
This removes the functions/completions that were using the deprecated
--ignore-unknown option and replaces it with the new --move-unknown.
Although some of the code is now more verbose, it has improved the
functionality of two completions:
the iwctl completion will now skip over options when detecting
what subcommand is being used
the ninja completion wil now handle -- correctly: if the completion
internally invokes ninja, it will correctly interpret the users
arguments as being arguments if they start with a - and occur
after the --.
This commit is contained in:
@@ -29,9 +29,9 @@ function __fish_conda_subcommand
|
|||||||
# get the commandline args without the "conda"
|
# get the commandline args without the "conda"
|
||||||
set -l toks (commandline -xpc)[2..-1]
|
set -l toks (commandline -xpc)[2..-1]
|
||||||
|
|
||||||
# Remove any important options - if we had options with arguments,
|
# if we had options with arguments,
|
||||||
# they'd need to be listed here to be removed.
|
# they'd need to be listed here to be removed.
|
||||||
argparse -i h/help v/version -- $toks 2>/dev/null
|
argparse -u -- $toks 2>/dev/null
|
||||||
# Return false if it fails - this shouldn't really happen,
|
# Return false if it fails - this shouldn't really happen,
|
||||||
# so all bets are off
|
# so all bets are off
|
||||||
or return 2
|
or return 2
|
||||||
@@ -44,19 +44,12 @@ function __fish_conda_subcommand
|
|||||||
if test "$subcmds[1]" = "$argv[1]"
|
if test "$subcmds[1]" = "$argv[1]"
|
||||||
set -e argv[1]
|
set -e argv[1]
|
||||||
set -e subcmds[1]
|
set -e subcmds[1]
|
||||||
else if string match -q -- '-*' $argv[1]
|
|
||||||
set -e argv[1]
|
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Skip any remaining options.
|
# If we have no subcommand
|
||||||
while string match -q -- '-*' $argv[1]
|
|
||||||
set -e argv[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
# If we have no subcommand left,
|
|
||||||
# we either matched all given subcommands or we need one.
|
# we either matched all given subcommands or we need one.
|
||||||
if not set -q argv[1]
|
if not set -q argv[1]
|
||||||
return $have_sub
|
return $have_sub
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ function __iwctl_filter -w iwctl
|
|||||||
# awk does not work on multiline entries, therefore we use string match,
|
# awk does not work on multiline entries, therefore we use string match,
|
||||||
# which has the added benefit of filtering out the `No devices in ...` lines
|
# which has the added benefit of filtering out the `No devices in ...` lines
|
||||||
|
|
||||||
argparse -i all-columns -- $argv
|
argparse -u all-columns -- $argv
|
||||||
|
|
||||||
# remove color escape sequences
|
# remove color escape sequences
|
||||||
set -l results (iwctl $argv | string replace -ra '\e\[[\d;]+m' '')
|
set -l results (iwctl $argv_opts -- $argv | string replace -ra '\e\[[\d;]+m' '')
|
||||||
# calculate column widths
|
# calculate column widths
|
||||||
set -l headers $results[3]
|
set -l headers $results[3]
|
||||||
# We exploit the fact that all column labels will have >2 space to the left, and inside column labels there is always only one space.
|
# We exploit the fact that all column labels will have >2 space to the left, and inside column labels there is always only one space.
|
||||||
@@ -38,7 +38,7 @@ function __iwctl_match_subcoms
|
|||||||
|
|
||||||
set argv (commandline -pxc)
|
set argv (commandline -pxc)
|
||||||
# iwctl allows to specify arguments for username, password, passphrase and dont-ask regardless of any following commands
|
# iwctl allows to specify arguments for username, password, passphrase and dont-ask regardless of any following commands
|
||||||
argparse -i 'u/username=' 'p/password=' 'P/passphrase=' v/dont-ask -- $argv
|
argparse -u 'u/username=' 'p/password=' 'P/passphrase=' v/dont-ask -- $argv
|
||||||
set argv $argv[2..]
|
set argv $argv[2..]
|
||||||
|
|
||||||
if test (count $argv) != (count $match)
|
if test (count $argv) != (count $match)
|
||||||
@@ -55,7 +55,7 @@ end
|
|||||||
function __iwctl_connect
|
function __iwctl_connect
|
||||||
set argv (commandline -pxc)
|
set argv (commandline -pxc)
|
||||||
# remove all options
|
# remove all options
|
||||||
argparse -i 'u/username=' 'p/password=' 'P/passphrase=' v/dont-ask -- $argv
|
argparse -u 'u/username=' 'p/password=' 'P/passphrase=' v/dont-ask -- $argv
|
||||||
# station name should now be the third argument (`iwctl station <wlan>`)
|
# station name should now be the third argument (`iwctl station <wlan>`)
|
||||||
for network in (__iwctl_filter station $argv[3] get-networks rssi-dbms --all-columns)
|
for network in (__iwctl_filter station $argv[3] get-networks rssi-dbms --all-columns)
|
||||||
set network (string split \t -- $network)
|
set network (string split \t -- $network)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ end
|
|||||||
function __fish_meson_builddir
|
function __fish_meson_builddir
|
||||||
# Consider the value of -C option to detect the build directory
|
# Consider the value of -C option to detect the build directory
|
||||||
set -l cmd (commandline -xpc)
|
set -l cmd (commandline -xpc)
|
||||||
argparse -i 'C=' -- $cmd
|
argparse -u 'C=' -- $cmd
|
||||||
if set -q _flag_C
|
if set -q _flag_C
|
||||||
echo $_flag_C
|
echo $_flag_C
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
function __fish_ninja
|
function __fish_ninja
|
||||||
set -l saved_args $argv
|
set -l saved_args $argv
|
||||||
set -l dir .
|
set -l dir .
|
||||||
if argparse -i C/dir= -- (commandline -xpc)
|
if argparse -u C/dir= -- (commandline -xpc)
|
||||||
command ninja -C$_flag_C $saved_args
|
command ninja -C$_flag_C $saved_args
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -61,11 +61,13 @@ function __fish_complete_yadm_like_git
|
|||||||
set -l yadm_work_tree (yadm gitconfig --get core.worktree)
|
set -l yadm_work_tree (yadm gitconfig --get core.worktree)
|
||||||
set -l yadm_repo (yadm introspect repo)
|
set -l yadm_repo (yadm introspect repo)
|
||||||
|
|
||||||
argparse -i 'R-yadm-repo=' -- $cmdline 2>/dev/null
|
argparse -u 'R-yadm-repo=&' -- $cmdline 2>/dev/null
|
||||||
if set -q _flag_yadm_repo
|
if set -q _flag_yadm_repo
|
||||||
set yadm_repo $_flag_yadm_repo
|
set yadm_repo $_flag_yadm_repo
|
||||||
# argparse *always* sets $argv to remaining arguments after consuming specified options
|
# argparse -u *always* sets $argv to remaining arguments after consuming all options,
|
||||||
set cmdline $argv
|
# and it *always* sets $argv_opts to any specified non-& options and any unknown options
|
||||||
|
# (the -- is needed in case $argv originally contained a -- followed by arguments starting with a -)
|
||||||
|
set cmdline $argv_opts -- $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
set -l git_wrapper_cmd "git --work-tree $yadm_work_tree --git-dir $yadm_repo $cmdline"
|
set -l git_wrapper_cmd "git --work-tree $yadm_work_tree --git-dir $yadm_repo $cmdline"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
function __fish_mysql_query -a query
|
function __fish_mysql_query -a query
|
||||||
argparse -i 'u/user=' 'P/port=' 'h/host=' 'p/password=?' 'S/socket=' -- (commandline -px)
|
argparse -u 'u/user=' 'P/port=' 'h/host=' 'p/password=?' 'S/socket=' -- (commandline -px)
|
||||||
set -l mysql_cmd mysql
|
set -l mysql_cmd mysql
|
||||||
for flag in u P h S
|
for flag in u P h S
|
||||||
if set -q _flag_$flag
|
if set -q _flag_$flag
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
function __fish_seen_argument --description 'Check whether argument is used'
|
function __fish_seen_argument --description 'Check whether argument is used'
|
||||||
argparse --ignore-unknown 's/short=+' 'o/old=+' 'l/long=+' 'w/windows=+' -- $argv
|
argparse --move-unknown 's/short=+&' 'o/old=+&' 'l/long=+&' 'w/windows=+&' -- $argv
|
||||||
|
|
||||||
set --local tokens (commandline --current-process --tokens-expanded --cut-at-cursor)
|
set --local tokens (commandline --current-process --tokens-expanded --cut-at-cursor)
|
||||||
set --erase tokens[1]
|
set --erase tokens[1]
|
||||||
@@ -30,7 +30,7 @@ function __fish_seen_argument --description 'Check whether argument is used'
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for raw_arg in $argv
|
for raw_arg in $argv_opts $argv
|
||||||
if string match --quiet -- $t $raw_arg
|
if string match --quiet -- $t $raw_arg
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user