-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathzsh_prompt
More file actions
138 lines (116 loc) · 3.41 KB
/
Copy pathzsh_prompt
File metadata and controls
138 lines (116 loc) · 3.41 KB
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
vi-git-status() {
local action="${hook_com[action]}"
if [[ -n $action ]]; then
if [[ "$action" == "rebase" ]]; then
hook_com[misc]=""
elif [[ "$action" == "rebase-i" ]]; then
hook_com[misc]=""
elif [[ "$action" == "merge" ]]; then
hook_com[misc]=""
fi
else
hook_com[misc]=""
fi
}
_segment() {
local bg=$1 fg=$2 text=$3 indent=$4
local segment="%K{$bg}%F{$fg}%B$text%b%f%k"
echo -ne "$segment"
}
_generate_prompt() {
local prompt_content="${prompt_newline}"
local working_tree="${vcs_info_msg_1_}"
# •
# ↪
# ↳
# ∼
#
# ✕
#
#
#
#
#
# ╭────────────────────────╮
# │$ Main : hackerone/core │
# ╰────────────────────────╯
#
# Main hackerone/core $
#
if [[ -n "$SSH_CONNECTION" ]]; then
prompt_content+=$( _segment 'default' 'red' " %m" 0)
fi
# VCS info
if [[ -n $working_tree ]]; then
if [[ ${git_dirty:-0} -eq 0 ]]; then
prompt_content+=$(_segment 'default' 'default' "${vcs_info_msg_0_}" $SSH_CONNECTION)
else
prompt_content+=$(_segment 'default' 'default' "${vcs_info_msg_0_}* " $SSH_CONNECTION)
fi
fi
# prompt_content+="%(?. . )"
# Add last exit code indicator
# Add current directory indicator
prompt_content+=$(_segment 'default' '#484848' ' %(3~|%2~|%~)' $working_tree)
PROMPT="${(j..)prompt_content} %B$%b "
}
_prompt_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
else
echo -ne "\033[1m--- FILES:\033[0m \n"
CLICOLOR_FORCE=1 ls -C -G | less -XFR
echo -n "\n"
fi
zle redisplay
else
zle accept-line
fi
}
# Update vcs information only when inside a git repository
_update_vcs_info() {
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
vcs_info
if git status --porcelain=2 --untracked-files=no --ignore-submodules | grep -q .; then
git_dirty=1
else
git_dirty=0
fi
else
unset vcs_info_msg_0_ vcs_info_msg_1_ vcs_info_msg_2_
unset git_dirty
fi
}
prompt_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 _update_vcs_info
add-zsh-hook precmd _generate_prompt # generate left side prompt
# zle -N zle-line-init _ombre_line_init
# zle -N zle-keymap-select _prompt_keymap_select
zle -N buffer-empty _prompt_buffer_empty
bindkey -M main "^M" buffer-empty
bindkey -M vicmd "^M" buffer-empty
bindkey -M viins "^M" buffer-empty
}
prompt_setup "$@"