77813a330bbc716503dcc4d8d98b6d8ae6f74d03
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
avit: clean up theme code
Diff
1diff --git a/themes/avit.zsh-theme b/themes/avit.zsh-theme
2index 3179bd837833c529cdc17751c70a1c87f738246f..4f82f34140d8152340767bee5764f609a334d096 100644
3--- a/themes/avit.zsh-theme
4+++ b/themes/avit.zsh-theme
5@@ -1,27 +1,20 @@
6 # AVIT ZSH Theme
7
8+# settings
9+typeset +H _current_dir="%{$fg_bold[blue]%}%3~%{$reset_color%} "
10+typeset +H _return_status="%{$fg_bold[red]%}%(?..⍉)%{$reset_color%}"
11+typeset +H _hist_no="%{$fg[grey]%}%h%{$reset_color%}"
12+
13 PROMPT='
14 $(_user_host)${_current_dir} $(git_prompt_info) $(ruby_prompt_info)
15-%{$fg[$CARETCOLOR]%}▶%{$resetcolor%} '
16+%{%F{%(!.red.white)}%}▶%{$resetcolor%} '
17
18-PROMPT2='%{$fg[$CARETCOLOR]%}◀%{$reset_color%} '
19+PROMPT2='%{%F{%(!.red.white)}%}◀%{$reset_color%} '
20
21 RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}'
22
23-local _current_dir="%{$fg_bold[blue]%}%3~%{$reset_color%} "
24-local _return_status="%{$fg_bold[red]%}%(?..⍉)%{$reset_color%}"
25-local _hist_no="%{$fg[grey]%}%h%{$reset_color%}"
26-
27-function _current_dir() {
28- local _max_pwd_length="65"
29- if [[ $(echo -n $PWD | wc -c) -gt ${_max_pwd_length} ]]; then
30- echo "%{$fg_bold[blue]%}%-2~ ... %3~%{$reset_color%} "
31- else
32- echo "%{$fg_bold[blue]%}%~%{$reset_color%} "
33- fi
34-}
35-
36 function _user_host() {
37+ local me
38 if [[ -n $SSH_CONNECTION ]]; then
39 me="%n@%m"
40 elif [[ $LOGNAME != $USER ]]; then
41@@ -35,39 +28,29 @@ function _user_host() {
42 # Determine the time since last commit. If branch is clean,
43 # use a neutral color, otherwise colors will vary according to time.
44 function _git_time_since_commit() {
45-# Only proceed if there is actually a commit.
46+ local last_commit now seconds_since_last_commit
47+ local minutes hours commit_age
48+ # Only proceed if there is actually a commit.
49 if last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null); then
50 now=$(date +%s)
51 seconds_since_last_commit=$((now-last_commit))
52
53 # Totals
54 minutes=$((seconds_since_last_commit / 60))
55- hours=$((seconds_since_last_commit/3600))
56-
57- # Sub-hours and sub-minutes
58- days=$((seconds_since_last_commit / 86400))
59- sub_hours=$((hours % 24))
60- sub_minutes=$((minutes % 60))
61+ hours=$((seconds_since_last_commit / 3600))
62
63- if [ $hours -ge 24 ]; then
64- commit_age="${days}d"
65- elif [ $minutes -gt 60 ]; then
66- commit_age="${sub_hours}h${sub_minutes}m"
67+ if [[ $hours -ge 24 ]]; then
68+ commit_age="$(( hours / 24 ))d"
69+ elif [[ $hours -gt 0 ]]; then
70+ commit_age+="$(( hours % 24 ))h$(( minutes % 60 ))m"
71 else
72 commit_age="${minutes}m"
73 fi
74
75- color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL
76- echo "$color$commit_age%{$reset_color%}"
77+ echo "${ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL}${commit_age}%{$reset_color%}"
78 fi
79 }
80
81-if [[ $USER == "root" ]]; then
82- CARETCOLOR="red"
83-else
84- CARETCOLOR="white"
85-fi
86-
87 MODE_INDICATOR="%{$fg_bold[yellow]%}❮%{$reset_color%}%{$fg[yellow]%}❮❮%{$reset_color%}"
88
89 # Git prompt settings