2006-02-08 09:20:05 +00:00
#
# This is a neat function, stolen from zsh. It allows you to edit the
# value of a variable interactively.
#
2007-01-16 01:29:18 +00:00
function vared --description "Edit variable value"
2006-02-08 09:20:05 +00:00
if test ( count $argv ) = 1
switch $argv
case '-h' '--h' '--he' '--hel' '--help'
2006-11-17 16:24:38 +00:00
__fish_print_help vared
return 0
2006-02-08 09:20:05 +00:00
case '-*'
printf ( _ "%s: Unknown option %s\n" ) vared $argv
2006-11-17 16:24:38 +00:00
return 1
2006-02-08 09:20:05 +00:00
case '*'
if test ( count $$ argv ) -lt 2
2007-02-08 17:01:18 +00:00
set -l init ''
2006-02-08 09:20:05 +00:00
if test $$ argv
2006-12-12 20:37:27 +00:00
set init $$ argv
2006-02-08 09:20:05 +00:00
end
2007-02-08 17:01:18 +00:00
set -l prompt 'set_color green; echo ' $argv '; set_color normal; echo "> "'
if read -p $prompt -c $init tmp
# If variable already exists, do not add any
# switches, so we don't change export rules. But
# if it does not exist, we make the variable
# global, so that it will not die when this
# function dies
if test $$ argv
set $argv $tmp
else
set -g $argv $tmp
end
2006-02-08 09:20:05 +00:00
end
else
2014-03-03 21:17:55 +00:00
printf ( _ '%s: %s is an array variable. Use %svared%s %s[n] to edit the n:th element of %s\n' ) vared $argv ( set_color $fish_color_command ; echo ) ( set_color $fish_color_normal ; echo ) $argv $argv
2006-02-08 09:20:05 +00:00
end
end
else
2014-03-03 21:17:55 +00:00
printf ( _ '%s: Expected exactly one argument, got %s.\n\nSynopsis:\n\t%svared%s VARIABLE\n' ) vared ( count $argv ) ( set_color $fish_color_command ; echo ) ( set_color $fish_color_normal ; echo )
2006-02-08 09:20:05 +00:00
end
end