1 # Copy this file into /usr/share/zsh/site-functions/
2 # and add 'autoload n-options` to .zshrc
4 # This function allows to browse and toggle shell's options
15 unset NLIST_COLORING_PATTERN
17 [ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
18 [ -f ~/.config/znt/n-options.conf ] && builtin source ~/.config/znt/n-options.conf
20 # TODO restore options
23 integer kshoptionprint=0
24 [[ -o kshoptionprint ]] && kshoptionprint=1
32 # 0 - don't remember, 1 - remember, 2 - init once, then remember
33 NLIST_REMEMBER_STATE=2
35 local NLIST_GREP_STRING="${1:=}"
39 list=( "${(M)list[@]:#*${1:=}*}" )
40 list=( "${list[@]:#kshoptionprint*}" )
42 if [ "$#list" -eq 0 ]; then
43 echo "No matching options"
47 local red=$'\x1b[00;31m' green=$'\x1b[00;32m' reset=$'\x1b[00;00m'
48 list=( "${list[@]/ off/${red} off$reset}" )
49 #list=( "${list[@]/ on/${green} on$reset}" )
50 list=( "${(i)list[@]}" )
54 if [ "$REPLY" -gt 0 ]; then
55 [[ -o ksharrays ]] && selected="${reply[$(( REPLY - 1 ))]}" || selected="${reply[$REPLY]}"
56 option="${selected%% *}"
57 state="${selected##* }"
59 if [[ -o globsubst ]]; then
61 state="${state%$reset}"
64 state="${state%$reset}"
68 if [ "$state" = "on" ]; then
69 echo "Setting |$option| to off"
72 echo "Setting |$option| to on"
80 NLIST_REMEMBER_STATE=0
82 [[ "$kshoptionprint" -eq 0 ]] && unsetopt kshoptionprint
84 # vim: set filetype=zsh: