diff options
author | axel <axel@liljencrantz.se> | 2006-02-17 20:13:39 +1000 |
---|---|---|
committer | axel <axel@liljencrantz.se> | 2006-02-17 20:13:39 +1000 |
commit | 343cafef346543282b5b6e825bc8f9dd10028a48 (patch) | |
tree | 1bcf221ecb525c7aeadc8325e7b780d3656e544b /share/functions/vared.fish | |
parent | 95a01f3c8f15034433ffce368d8f2d13d925139c (diff) |
Redo installation file structure, move lots of things to $PREFIX/share/fish
darcs-hash:20060217101339-ac50b-d93d2c620a4b7f75f05ff461a6edbee001da7613.gz
Diffstat (limited to 'share/functions/vared.fish')
-rw-r--r-- | share/functions/vared.fish | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/share/functions/vared.fish b/share/functions/vared.fish new file mode 100644 index 00000000..b9414d84 --- /dev/null +++ b/share/functions/vared.fish @@ -0,0 +1,47 @@ + +# +# This is a neat function, stolen from zsh. It allows you to edit the +# value of a variable interactively. +# + +function vared -d (_ "Edit variable value") + if test (count $argv) = 1 + switch $argv + + case '-h' '--h' '--he' '--hel' '--help' + help vared + + case '-*' + printf (_ "%s: Unknown option %s\n") vared $argv + + case '*' + if test (count $$argv ) -lt 2 + set init '' + if test $$argv + set -- init $$argv + end + set prompt 'set_color green; echo '$argv'; set_color normal; echo "> "' + 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 + + else + + printf (_ '%s: %s is an array variable. Use %svared%s %s[n] to edit the n:th element of %s\n') $argv (set_color $fish_color_command) (set_color $fish_color_normal) vared $argv $argv + end + end + else + printf (_ '%s: Expected exactly one argument, got %s.\n\nSynopsis:\n\t%svared%s VARIABLE\n') vared (count $argv) (set_color $fish_color_command) (set_color $fish_color_normal) + end +end + |