mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Overhaul completions for set
and add new completions for set -e
Now the description includes the variable scope, `set [-e] -[Ugl]` completions only provide variables matching that scope, and completions that shouldn't be modified are hidden from the user. Completions that are often modified but rarely unset (`fish_*` variables) are omitted from `set -e` completions. A new helper function `__fish_seen_argument` has been added that makes it easy to only provied completions for a specific flag.
This commit is contained in:
parent
cc50103e53
commit
c492d03f51
2 changed files with 41 additions and 3 deletions
|
@ -40,6 +40,7 @@ function __fish_set_is_locale -d 'Test if We are specifying a locale value for t
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
case '-*'
|
case '-*'
|
||||||
|
continue
|
||||||
|
|
||||||
case '*'
|
case '*'
|
||||||
return 1
|
return 1
|
||||||
|
@ -65,9 +66,25 @@ complete -c set -n '__fish_is_first_token' -s q -l query -d "Test if variable is
|
||||||
complete -c set -n '__fish_is_first_token' -s h -l help -d "Display help and exit"
|
complete -c set -n '__fish_is_first_token' -s h -l help -d "Display help and exit"
|
||||||
complete -c set -n '__fish_is_first_token' -s n -l names -d "List the names of the variables, but not their value"
|
complete -c set -n '__fish_is_first_token' -s n -l names -d "List the names of the variables, but not their value"
|
||||||
|
|
||||||
|
#TODO: add CPP code to generate list of read-only variables and exclude them from the following completions
|
||||||
|
|
||||||
# Complete using preexisting variable names
|
# Complete using preexisting variable names
|
||||||
complete -c set -n '__fish_is_first_token' -x -a "(set|sed -e 's/ /'\t'Variable: /')"
|
complete -c set -n '__fish_is_first_token; and not __fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s g -s U -l local -l global -l universal' -x -a "(set -l | string match -rv '^__' | string replace ' ' \t'Local Variable: ')"
|
||||||
|
complete -c set -n '__fish_is_first_token; and not __fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s g -s U -l local -l global -l universal' -x -a "(set -g | string match -rv '^__' | string replace ' ' \t'Global Variable: ')"
|
||||||
|
complete -c set -n '__fish_is_first_token; and not __fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s g -s U -l local -l global -l universal' -x -a "(set -U | string match -rv '^__' | string replace ' ' \t'Universal Variable: ')"
|
||||||
|
# Complete scope-specific variables
|
||||||
|
complete -c set -n '__fish_is_first_token; and __fish_seen_argument -s l -l local' -x -a "(set -l | string match -rv '^__' | string replace ' ' \t'Local Variable: ')"
|
||||||
|
complete -c set -n '__fish_is_first_token; and __fish_seen_argument -s g -l global' -x -a "(set -g | string match -rv '^__' | string replace ' ' \t'Global Variable: ')"
|
||||||
|
complete -c set -n '__fish_is_first_token; and __fish_seen_argument -s U -l universal' -x -a "(set -U | string match -rv '^__' | string replace ' ' \t'Universal Variable: ')"
|
||||||
|
|
||||||
|
# Complete using preexisting variable names for `set --erase`
|
||||||
|
complete -c set -n '__fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s U -s g -l local -l global -l Universal' -f -a "(set -g | string match -rv '^_|^fish_' | string replace ' ' \tGlobal\ Variable:\ )"
|
||||||
|
complete -c set -n '__fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s U -s g -l local -l global -l Universal' -f -a "(set -l | string match -rv '^_|^fish_' | string replace ' ' \tLocal\ Variable:\ )"
|
||||||
|
complete -c set -n '__fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s U -s g -l local -l global -l Universal' -f -a "(set -U | string match -rv '^_|^fish_' | string replace ' ' \tUniversal\ Variable:\ )"
|
||||||
|
# Complete scope-specific variables for `set --erase`
|
||||||
|
complete -c set -n '__fish_seen_argument -s e -l erase; and __fish_seen_argument -s g -l global' -f -a "(set -g | string match -rv '^_|^fish_' | string replace ' ' \t'Global Variable: ')"
|
||||||
|
complete -c set -n '__fish_seen_argument -s e -l erase; and __fish_seen_argument -s U -l universal' -f -a "(set -u | string match -rv '^_|^fish_' | string replace ' ' \t'Universal Variable: ')"
|
||||||
|
complete -c set -n '__fish_seen_argument -s e -l erase; and __fish_seen_argument -s l -l local' -f -a "(set -l | string match -rv '^_|^fish_' | string replace ' ' \t'Local Variable: ')"
|
||||||
|
|
||||||
# Color completions
|
# Color completions
|
||||||
complete -c set -n '__fish_set_is_color' -x -a '(set_color --print-colors)' -d Color
|
complete -c set -n '__fish_set_is_color' -x -a '(set_color --print-colors)' -d Color
|
||||||
|
@ -75,6 +92,5 @@ complete -c set -n '__fish_set_is_color' -s b -l background -x -a '(set_color --
|
||||||
complete -c set -n '__fish_set_is_color' -s o -l bold -d 'Make font bold'
|
complete -c set -n '__fish_set_is_color' -s o -l bold -d 'Make font bold'
|
||||||
|
|
||||||
# Locale completions
|
# Locale completions
|
||||||
complete -c set -n '__fish_is_first_token' -x -a '$__fish_locale_vars' -d 'Locale variable'
|
complete -c set -n '__fish_set_is_locale; and not __fish_seen_argument -s e -l erase' -x -a '(locale -a)' -d (_ "Locale")
|
||||||
complete -c set -n '__fish_set_is_locale' -x -a '(locale -a)' -d (_ "Locale")
|
|
||||||
complete -c set -s L -l long -d 'Do not truncate long lines'
|
complete -c set -s L -l long -d 'Do not truncate long lines'
|
||||||
|
|
22
share/functions/__fish_seen_argument.fish
Normal file
22
share/functions/__fish_seen_argument.fish
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
function __fish_seen_argument
|
||||||
|
argparse 's/short=+' 'l/long=+' -- $argv
|
||||||
|
|
||||||
|
set cmd (commandline -co)
|
||||||
|
set -e cmd[1]
|
||||||
|
for t in $cmd
|
||||||
|
for s in $_flag_s
|
||||||
|
if string match -qr "^-[A-z0-9]*"$s"[A-z0-9]*\$" -- $t
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for l in $_flag_l
|
||||||
|
if string match -q "--$l" -- $t
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue