-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt.zsh
59 lines (50 loc) · 1.44 KB
/
prompt.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
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
# Setup my prompt and built-in keybindings
# setup prompt
parse_git_branch() {
local BRANCH_NAME
BRANCH_NAME="$(git symbolic-ref --short HEAD 2>/dev/null)"
(($? == 0)) && echo -n " | %{%F{green}%}${BRANCH_NAME}%{%F{none}%}\n"
}
precmd_functions=("_exit_status" ${precmd_functions[@]})
_exit_status() {
local last_exit_status=$?
last_exit=""
if ((last_exit_status != 0)); then
last_exit=" | %F{red}${last_exit_status}%f"
fi
export last_exit
}
setopt PROMPT_SUBST
PROMPT='[ %9c$(parse_git_branch)$last_exit ] $ '
# Change cursor shape for different vi modes.
function zle-keymap-select() {
if [[ ${KEYMAP} == vicmd ]] ||
[[ $1 = 'block' ]]; then
echo -ne '\e[1 q'
elif [[ ${KEYMAP} == main ]] ||
[[ ${KEYMAP} == viins ]] ||
[[ ${KEYMAP} = '' ]] ||
[[ $1 = 'beam' ]]; then
echo -ne '\e[5 q'
fi
}
zle -N zle-keymap-select
zle-line-init() {
zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
echo -ne '\e[5 q'
}
zle -N zle-line-init
# vim style bindings
# Escape to enter command mode
export KEYTIMEOUT=1
bindkey -v
bindkey -v '^?' backward-delete-char # allow backspace to delete items after exiting command mode
# basic readline bindings
bindkey '^A' vi-beginning-of-line
bindkey '^E' vi-end-of-line
bindkey '^K' vi-kill-eol
# press space in vi command mode
# to open current command in a vimbuffer
autoload -z edit-command-line
zle -N edit-command-line
bindkey -M vicmd ' ' edit-command-line