-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoas.plugin.zsh
32 lines (31 loc) · 884 Bytes
/
doas.plugin.zsh
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
# ------------------------------------------------------------------------------
# Description
# -----------
#
# doas will be inserted before the command
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Anatoly <[email protected]>
#
# ------------------------------------------------------------------------------
doas-command-line() {
[[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)"
if [[ $BUFFER == doas\ * ]]; then
if [[ ${#LBUFFER} -le 4 ]]; then
RBUFFER="${BUFFER#doas }"
LBUFFER=""
else
LBUFFER="${LBUFFER#doas }"
fi
else
LBUFFER="doas $LBUFFER"
fi
}
zle -N doas-command-line
# Defined shortcut keys: [Esc] [Esc]
bindkey -M emacs '\e\e' doas-command-line
bindkey -M vicmd '\e\e' doas-command-line
bindkey -M viins '\e\e' doas-command-line