Commit 77813a33 authored by Marc Cornellà's avatar Marc Cornellà
Browse files

avit: clean up theme code

parent 443ad880
# AVIT ZSH Theme # AVIT ZSH Theme
# settings
typeset +H _current_dir="%{$fg_bold[blue]%}%3~%{$reset_color%} "
typeset +H _return_status="%{$fg_bold[red]%}%(?..⍉)%{$reset_color%}"
typeset +H _hist_no="%{$fg[grey]%}%h%{$reset_color%}"
PROMPT=' PROMPT='
$(_user_host)${_current_dir} $(git_prompt_info) $(ruby_prompt_info) $(_user_host)${_current_dir} $(git_prompt_info) $(ruby_prompt_info)
%{$fg[$CARETCOLOR]%}▶%{$resetcolor%} ' %{%F{%(!.red.white)}%}▶%{$resetcolor%} '
PROMPT2='%{$fg[$CARETCOLOR]%}◀%{$reset_color%} ' PROMPT2='%{%F{%(!.red.white)}%}◀%{$reset_color%} '
RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}' RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}'
local _current_dir="%{$fg_bold[blue]%}%3~%{$reset_color%} "
local _return_status="%{$fg_bold[red]%}%(?..⍉)%{$reset_color%}"
local _hist_no="%{$fg[grey]%}%h%{$reset_color%}"
function _current_dir() {
local _max_pwd_length="65"
if [[ $(echo -n $PWD | wc -c) -gt ${_max_pwd_length} ]]; then
echo "%{$fg_bold[blue]%}%-2~ ... %3~%{$reset_color%} "
else
echo "%{$fg_bold[blue]%}%~%{$reset_color%} "
fi
}
function _user_host() { function _user_host() {
local me
if [[ -n $SSH_CONNECTION ]]; then if [[ -n $SSH_CONNECTION ]]; then
me="%n@%m" me="%n@%m"
elif [[ $LOGNAME != $USER ]]; then elif [[ $LOGNAME != $USER ]]; then
...@@ -35,39 +28,29 @@ function _user_host() { ...@@ -35,39 +28,29 @@ function _user_host() {
# Determine the time since last commit. If branch is clean, # Determine the time since last commit. If branch is clean,
# use a neutral color, otherwise colors will vary according to time. # use a neutral color, otherwise colors will vary according to time.
function _git_time_since_commit() { function _git_time_since_commit() {
# Only proceed if there is actually a commit. local last_commit now seconds_since_last_commit
local minutes hours commit_age
# Only proceed if there is actually a commit.
if last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null); then if last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null); then
now=$(date +%s) now=$(date +%s)
seconds_since_last_commit=$((now-last_commit)) seconds_since_last_commit=$((now-last_commit))
# Totals # Totals
minutes=$((seconds_since_last_commit / 60)) minutes=$((seconds_since_last_commit / 60))
hours=$((seconds_since_last_commit/3600)) hours=$((seconds_since_last_commit / 3600))
# Sub-hours and sub-minutes
days=$((seconds_since_last_commit / 86400))
sub_hours=$((hours % 24))
sub_minutes=$((minutes % 60))
if [ $hours -ge 24 ]; then if [[ $hours -ge 24 ]]; then
commit_age="${days}d" commit_age="$(( hours / 24 ))d"
elif [ $minutes -gt 60 ]; then elif [[ $hours -gt 0 ]]; then
commit_age="${sub_hours}h${sub_minutes}m" commit_age+="$(( hours % 24 ))h$(( minutes % 60 ))m"
else else
commit_age="${minutes}m" commit_age="${minutes}m"
fi fi
color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL echo "${ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL}${commit_age}%{$reset_color%}"
echo "$color$commit_age%{$reset_color%}"
fi fi
} }
if [[ $USER == "root" ]]; then
CARETCOLOR="red"
else
CARETCOLOR="white"
fi
MODE_INDICATOR="%{$fg_bold[yellow]%}❮%{$reset_color%}%{$fg[yellow]%}❮❮%{$reset_color%}" MODE_INDICATOR="%{$fg_bold[yellow]%}❮%{$reset_color%}%{$fg[yellow]%}❮❮%{$reset_color%}"
# Git prompt settings # Git prompt settings
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment