-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongsilvern.zsh-theme
96 lines (78 loc) · 2.77 KB
/
longsilvern.zsh-theme
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
declare GIT_PROMPT_BEHIND="%{$fg[red]%}⇣"
declare GIT_PROMPT_DIRTY="%{$fg[yellow]%}*"
declare GIT_PROMPT_AHEAD="%{$fg[green]%}⇡"
declare GIT_PROMPT_CLEAN="%{$reset_color%}"
function checkGitStatus() {
declare STATUS="$GIT_PROMPT_CLEAN"
if [[ -n $(git log origin/$(git_current_branch)..HEAD 2> /dev/null) ]]; then
STATUS+="$GIT_PROMPT_AHEAD"
fi
if [[ -n $(git status -s) ]]; then
STATUS+="$GIT_PROMPT_DIRTY"
fi
if [[ -n $(git log HEAD..origin/$(git_current_branch) 2> /dev/null) ]]; then
STATUS+="$GIT_PROMPT_BEHIND"
fi
echo "$STATUS"
}
# Show execution time after each command
function preexec() {
timer=$(( $(date +%s) ))
}
function precmd() {
if [ $timer ]; then
now=$(( $(date +%s) ))
elapsedSecs=$(( $now-$timer ))
unset timer
# Only show execution time if more than 1 second
if [[ "$elapsedSecs" -gt 1 ]]; then
timeStringColour="%{$fg[green]%}"
timeString="${elapsedSecs}s"
declare -i hours
declare -i mins
declare -i secs
# Yellow colour warning where execution is longer than 1 minute
if [[ "$elapsedSecs" -ge 60 ]]; then
timeStringColour="%{$fg[yellow]%}"
mins=$(( $elapsedSecs%3600/60 ))
secs=$(( $elapsedSecs%60 ))
timeString="${mins}m ${secs}s"
fi
# Red colour warning where execution is longer than 5 minutes
if [[ "$elapsedSecs" -ge 300 ]]; then
timeStringColour="%{$fg[red]%}"
fi
if [[ "$elapsedSecs" -ge 3600 ]]; then
hours=$(( $elapsedSecs/3600 ))
timeString="${hours}h ${mins}m ${secs}s"
fi
RPROMPT="$timeStringColour$timeString %{$reset_color%}"
else
RPROMPT=""
fi
export RPROMPT
fi
}
#------------------- PROMPT ---------------------
function timeStampPrompt() {
echo "%{$fg_bold[magenta]%}%T|%{$reset_color%}"
}
# If the path contains more than 4 directories, omit the middle path using ellipsis
function compactPathPrompt() {
declare maximumElements=4
declare displayElements=2
echo "%{$fg[cyan]%}%($maximumElements~|%-1~/…/%$displayElements~|%$((DISPLAY_ELEMENTS++))~)%{$reset_color%}"
}
declare GIT_PROMPT_PREFIX="%{$fg[blue]%}⦗"
declare GIT_PROMPT_SUFFIX="%{$fg[blue]%}⦘%{$reset_color%}"
function gitStatusPrompt() {
if $(git rev-parse --is-inside-work-tree 2>/dev/null); then
# Compact the branch name when it is longer than maxinum length
max_branch_name_length=18
echo "$GIT_PROMPT_PREFIX%$max_branch_name_length>…>$(checkGitStatus)$(git_current_branch)%>>$GIT_PROMPT_SUFFIX"
else
echo ""
fi
}
PROMPT='$(timeStampPrompt)$(compactPathPrompt) $(gitStatusPrompt) '
PROMPT+='%(?:%{$fg_bold[green]%}➜:%{$fg_bold[red]%}➜) '