123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- # Copy this file into /usr/share/zsh/site-functions/
- # and add 'autoload n-options` to .zshrc
- #
- # This function allows to browse and toggle shell's options
- #
- # Uses n-list
- #emulate -L zsh
- zmodload zsh/curses
- local IFS="
- "
- unset NLIST_COLORING_PATTERN
- [ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
- [ -f ~/.config/znt/n-options.conf ] && builtin source ~/.config/znt/n-options.conf
- # TODO restore options
- unsetopt localoptions
- integer kshoptionprint=0
- [[ -o kshoptionprint ]] && kshoptionprint=1
- setopt kshoptionprint
- local list
- local selected
- local option
- local state
- # 0 - don't remember, 1 - remember, 2 - init once, then remember
- NLIST_REMEMBER_STATE=2
- local NLIST_GREP_STRING="${1:=}"
- while (( 1 )); do
- list=( `setopt` )
- list=( "${(M)list[@]:#*${1:=}*}" )
- list=( "${list[@]:#kshoptionprint*}" )
- if [ "$#list" -eq 0 ]; then
- echo "No matching options"
- break
- fi
- local red=$'\x1b[00;31m' green=$'\x1b[00;32m' reset=$'\x1b[00;00m'
- list=( "${list[@]/ off/${red} off$reset}" )
- #list=( "${list[@]/ on/${green} on$reset}" )
- list=( "${(i)list[@]}" )
- n-list "${list[@]}"
- if [ "$REPLY" -gt 0 ]; then
- [[ -o ksharrays ]] && selected="${reply[$(( REPLY - 1 ))]}" || selected="${reply[$REPLY]}"
- option="${selected%% *}"
- state="${selected##* }"
- if [[ -o globsubst ]]; then
- unsetopt globsubst
- state="${state%$reset}"
- setopt globsubst
- else
- state="${state%$reset}"
- fi
- # Toggle the option
- if [ "$state" = "on" ]; then
- echo "Setting |$option| to off"
- unsetopt "$option"
- else
- echo "Setting |$option| to on"
- setopt "$option"
- fi
- else
- break
- fi
- done
- NLIST_REMEMBER_STATE=0
- [[ "$kshoptionprint" -eq 0 ]] && unsetopt kshoptionprint
- # vim: set filetype=zsh:
|