-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.zsh
executable file
·62 lines (55 loc) · 1.68 KB
/
rc.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
60
61
62
# Below disables case sensitivity.
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
autoload -Uz compinit && compinit
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
setopt interactive_comments
autoload -U colors && colors
export VIRTUAL_ENV_DISABLE_PROMPT=1
# Credit for most of the prompt to Apeiros.
# (GitHub username: Apeiros-46B).
alias prompt_addins='printf "%s%s" "${IN_NIX_SHELL+❄ }" "${VIRTUAL_ENV+⚙ }"'
prompt_git() {
if git status 2>&- 1> /dev/null; then
branch="$(git -P branch | awk '{ print $2 }')"
if [ "$(git -P diff)" ]; then
print "%S%B $branch %s%F{0}%K{5} %k%f%b"
else print "%S%B $branch %s%F{0}%K{2} %k%f%b"
fi; exit 0
else exit 1; fi
}
precmd() {
PS1="%F{0}%B%(0?.%K{4} .%K{1} )%(1j.⚑ .)$(prompt_addins)%k%f%S %~ %b%s " ## Main Prompt
RPROMPT="$(prompt_git)" ## Git Prompt (Right)
}
PS2='%K{4} %S%B + %b%k%s ' ## Multiline Prompt
PS3='%K{4} %S%B select %b%k%s ' ## Select Prompt
# Credit for transient prompt goes to Roman Perepelitsa.
# (https://www.zsh.org/mla/users/2019/msg00633.html)
zle-line-init() {
emulate -L zsh
[[ $CONTEXT == start ]] || return 0
while true; do
zle .recursive-edit
local -i ret=$?
[[ $ret == 0 && $KEYS == $'\4' ]] || break
[[ -o ignore_eof ]] || exit 0
done
local saved_prompt=$PROMPT
local saved_rprompt=$RPROMPT
PROMPT="%F{0}%B%(0?.%K{4} .%K{1} )%b%k "
RPROMPT=""
zle .reset-prompt
PROMPT=$saved_prompt
RPROMPT=$saved_rprompt
if (( ret )); then
zle .send-break
else
zle .accept-line
fi
return ret
}
zle -N zle-line-init
if [[ -x "$(command -v zoxide)" ]]; then
eval "$(zoxide init zsh)"
fi