n-env
890 bytes
1# Copy this file into /usr/share/zsh/site-functions/
2# and add 'autoload n-env` to .zshrc
3#
4# This function allows to choose an environment variable
5# for edition with vared
6#
7# Uses n-list
8
9emulate -L zsh
10
11setopt extendedglob
12unsetopt equals
13zmodload zsh/curses
14
15local IFS="
16"
17
18[ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
19[ -f ~/.config/znt/n-env.conf ] && builtin source ~/.config/znt/n-env.conf
20
21local list
22local selected
23
24NLIST_REMEMBER_STATE=0
25
26list=( `env` )
27list=( "${(@M)list:#(#i)*$1*}" )
28
29local NLIST_GREP_STRING="$1"
30
31if [ "$#list" -eq 0 ]; then
32 echo "No matching variables"
33 return 1
34fi
35
36list=( "${(@i)list}" )
37n-list "$list[@]"
38
39if [ "$REPLY" -gt 0 ]; then
40 selected="$reply[REPLY]"
41 selected="${selected%%=*}"
42 echo "Editing \`$selected':"
43 print -rs "vared \"$selected\""
44 vared "$selected"
45fi
46
47# vim: set filetype=zsh: