diff options
author | Sebastian Gniazdowski <sgniazdowski@gmail.com> | 2015-09-20 14:39:46 +0200 |
---|---|---|
committer | Sebastian Gniazdowski <sgniazdowski@gmail.com> | 2015-11-01 16:10:55 +0100 |
commit | 4c292ea2b023a331dcf1af5644487f2272d24a4d (patch) | |
tree | 7141e282b7aaf9e5fba7ea3102c25ef0e5478d40 /plugins/zsh-navigation-tools/n-env | |
parent | 9c08641d7c2aae0c82fa5ad91f94c67b70115ba5 (diff) | |
download | zsh-4c292ea2b023a331dcf1af5644487f2272d24a4d.tar.gz zsh-4c292ea2b023a331dcf1af5644487f2272d24a4d.tar.bz2 zsh-4c292ea2b023a331dcf1af5644487f2272d24a4d.zip |
Initial commit of Zsh Navigation Tools
Diffstat (limited to 'plugins/zsh-navigation-tools/n-env')
-rw-r--r-- | plugins/zsh-navigation-tools/n-env | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/plugins/zsh-navigation-tools/n-env b/plugins/zsh-navigation-tools/n-env new file mode 100644 index 000000000..612796c00 --- /dev/null +++ b/plugins/zsh-navigation-tools/n-env @@ -0,0 +1,47 @@ +# Copy this file into /usr/share/zsh/site-functions/ +# and add 'autoload n-env` to .zshrc +# +# This function allows to choose an environment variable +# for edition with vared +# +# Uses n-list + +emulate -L zsh + +setopt extendedglob +unsetopt equals +zmodload zsh/curses + +local IFS=" +" + +[ -f ~/.config/znt/n-list.conf ] && . ~/.config/znt/n-list.conf +[ -f ~/.config/znt/n-env.conf ] && . ~/.config/znt/n-env.conf + +local list +local selected + +NLIST_REMEMBER_STATE=0 + +list=( `env` ) +list=( "${(@M)list:#(#i)*$1*}" ) + +local NLIST_GREP_STRING="$1" + +if [ "$#list" -eq 0 ]; then + echo "No matching variables" + return 1 +fi + +list=( "${(@i)list}" ) +n-list "$list[@]" + +if [ "$REPLY" -gt 0 ]; then + selected="$reply[REPLY]" + selected="${selected%%=*}" + echo "Editing \`$selected':" + print -rs "vared \"$selected\"" + vared "$selected" +fi + +# vim: set filetype=zsh: |