-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt_ombre_setup
142 lines (115 loc) · 3.63 KB
/
prompt_ombre_setup
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#/usr/bin/env zsh
# Git hooks {{{
# NOTE: Set highlighting based on dirty state
+vi-git-status() {
local action="${hook_com[action]}"
local action_symbol
# 梨 煮 ſt ﬗ ﯠ ﲋ
if [[ -n $action ]]; then
if [[ "$action" == "rebase" ]] || ; then
hook_com[misc]="%S "
# hook_com[misc]="%S "
elif [[ "$action" == "rebase-i" ]]; then
hook_com[misc]="%S "
# hook_com[misc]="%S "
elif [[ "$action" == "merge" ]]; then
hook_com[misc]="%S ﯠ"
# hook_com[misc]="%S "
fi
else
if ( test -z "$(command git status --porcelain --ignore-submodules -unormal)" ); then
hook_com[misc]="%S "
else
hook_com[misc]="%S "
fi
fi
}
# }}}
_generate_prompt() {
local prompt_content="${prompt_newline}"
# FIXME: instead of changing the prompt color,
# having a different shell color would be more awesome
# if [[ "$USER" == "root" ]]; then
# # prompt_sym="#"
# ok_color="red"
# else
# # prompt_sym=""
# ok_color="green"
# fi
# # get timestamp of command execution
# prompt_content+="%F{8}%*%f"
# Only print host name when connected through ssh
if [[ "$SSH_CONNECTION" != '' ]]; then
prompt_content+="%F{blue} %m%f"
fi
# Add last exit code indicator
prompt_content+="%(?. . )"
# Add vim mode indicator
prompt_content+="› "
PROMPT="${(j..)prompt_content}"
}
_generate_rprompt() {
local rprompt_content
local working_tree="${vcs_info_msg_1_}"
# construct prompt, beginning with path (only shows last two segments of ptah)
rprompt_content+=" %(3~|%2~|%~)"
# VCS info
if [[ -n $working_tree ]]; then
rprompt_content+="${vcs_info_msg_0_}"
fi
RPROMPT="%F{default}${rprompt_content}%f"
}
_ombre_keymap_select() {
[[ "$KEYMAP" == 'main' ]] && PROMPT="${PROMPT/·/›}"
[[ "$KEYMAP" == 'viins' ]] && PROMPT="${PROMPT/·/›}"
[[ "$KEYMAP" == 'vicmd' ]] && PROMPT="${PROMPT/›/·}"
zle reset-prompt
# zle -R
}
_ombre_buffer_empty() {
if [ -z "$BUFFER" ]; then
if [ -n "${vcs_info_msg_1_}" ]; then
echo -ne "\033[1m git status\033[0m \n"
git -c color.status=always status --ignore-submodules=all | less -XFR
git -c color.status=always lg -3 | less -XFR
fi
# echo -ne "\n \033[1m--- FILES:\033[0m \n"
# CLICOLOR_FORCE=1 ls -C -G | less -XFR
# echo -n "\n"
zle redisplay
else
zle accept-line
fi
}
prompt_ombre_setup() {
# prevent percentage showing up
# if output doesn't end with a newline
export PROMPT_EOL_MARK=''
setopt prompt_subst
# Borrowwed from sindresorhus/pure
if [[ -z $prompt_newline ]]; then
# This variable needs to be set, usually set by promptinit.
typeset -g prompt_newline=$'\n%{\r%}'
fi
zmodload zsh/datetime
zmodload zsh/zle
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' use-simple true
zstyle ':vcs_info:*' max-exports 3
zstyle ':vcs_info:git*' formats ' %m %0.20b %f%u%%s' '%R'
zstyle ':vcs_info:git*' actionformats ' %m %0.20b %f%u%%s' '%0.20b|%a' '%R'
zstyle ':vcs_info:git*+set-message:*' hooks git-status
add-zsh-hook precmd vcs_info
add-zsh-hook precmd _generate_prompt # generate prompt
add-zsh-hook precmd _generate_rprompt # generate prompt
# zle -N zle-line-init _ombre_line_init
zle -N zle-keymap-select _ombre_keymap_select
zle -N buffer-empty _ombre_buffer_empty
bindkey -M main "^M" buffer-empty
bindkey -M vicmd "^M" buffer-empty
bindkey -M viins "^M" buffer-empty
}
prompt_ombre_setup "$@"
# vim:ft=zsh foldlevel=0 foldmethod=marker