convert alias to use argparse

This commit is contained in:
Kurtis Rader
2017-07-13 11:41:00 -07:00
parent 05aae4764b
commit f156bea1b7

View File

@@ -1,10 +1,11 @@
function alias --description 'Creates a function wrapping a command' function alias --description 'Creates a function wrapping a command'
if count $argv >/dev/null set -l options 'h/help'
switch $argv[1] argparse -n alias --max-args=2 $options -- $argv
case -h --h --he --hel --help or return
__fish_print_help alias
return 0 if set -q _flag_help
end __fish_print_help alias
return 0
end end
set -l name set -l name
@@ -12,27 +13,25 @@ function alias --description 'Creates a function wrapping a command'
set -l prefix set -l prefix
set -l first_word set -l first_word
set -l wrapped_cmd set -l wrapped_cmd
switch (count $argv)
case 0 if not set -q argv[1]
for func in (functions -n) # Print the known aliases.
set -l output (functions $func | string match -r -- "function .* --description '(alias .*)'" | string split \n) for func in (functions -n)
set -q output[2] set -l output (functions $func | string match -r -- "function .* --description '(alias .*)'" | string split \n)
and echo $output[2] set -q output[2]
end and echo $output[2]
return 0 end
case 1 return 0
set -l tmp (string split -m 1 "=" -- $argv) "" else if not set -q argv[2]
set name $tmp[1] # Alias definition of the form "name=value".
set body $tmp[2] set -l tmp (string split -m 1 "=" -- $argv) ""
show $tmp
case 2 set name $tmp[1]
set name $argv[1] set body $tmp[2]
set body $argv[2] else
# Alias definition of the form "name value".
case \* set name $argv[1]
printf ( _ "%s: Expected one or two arguments, got %d\n") alias (count $argv) set body $argv[2]
return 1
end end
# sanity check # sanity check