forked from z-shell/zsh-navigation-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathn-options
84 lines (64 loc) · 1.89 KB
/
n-options
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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: