fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
867946468
master
1# localization: tier1 2 3# This is a neat function, stolen from zsh. It allows you to edit the 4# value of a variable interactively. 5# 6 7function vared --description"Edit variable value" 8if test ( count $argv ) = 1 9switch $argv 10 11case -h --h --he --hel --help 12__fish_print_help vared 13return 0 14 15case '-*' 16printf ( _ "%s: Unknown option %s\n" ) vared$argv >&2 17return 1 18 19case '*' 20if test ( count $$argv ) -lt 2 21# Try to avoid using local variables in this function, otherwise they can't be edited. 22# https://github.com/fish-shell/fish-shell/issues/8836 23# However we need to use one local, as you can't read directly into an index (like vared PATH[4]). 24set -l __fish_vared_temp_value 25 26# The command substitution in this line controls the scope. 27# If variable already exists, do not add any switches, so we don't change 28# scoping or export rules. But if it does not exist, we make the variable 29# global, so that it will not die when this function dies. 30 31read -p'set_color green; echo ' $argv '; set_color --reset; echo "> "' \ 32( if not set -q$argv ;echo -g;end ) \ 33 -c" $$argv " \ 34 __fish_vared_temp_value 35if test -n " $$argv " 36set $argv $__fish_vared_temp_value 37else 38set -g$argv $__fish_vared_temp_value 39end 40else 41printf ( _ '%s: %s is an array variable. Use %svared%s %s[n]%s to edit the n:th element of %s\n' ) vared$argv ( set_color $fish_color_command ;echo ) ( set_color $fish_color_normal ;echo ) $argv ( set_color --reset;echo ) $argv >&2 42end 43end 44else 45printf ( _ '%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 ) >&2 46end 47end