avit.zsh-theme 2.92 KB
Newer Older
Andrew Vit's avatar
Andrew Vit committed
1
2
# AVIT ZSH Theme

Marc Cornellà's avatar
Marc Cornellà committed
3
4
5
6
7
# 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%}"

Andrew Vit's avatar
Andrew Vit committed
8
PROMPT='
9
$(_user_host)${_current_dir} $(git_prompt_info) $(ruby_prompt_info)
10
%{%(!.${fg[red]}.${fg[white]})%}▶%{$reset_color%} '
Andrew Vit's avatar
Andrew Vit committed
11

12
PROMPT2='%{%(!.${fg[red]}.${fg[white]})%}◀%{$reset_color%} '
Andrew Vit's avatar
Andrew Vit committed
13

14
RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}'
Andrew Vit's avatar
Andrew Vit committed
15
16

function _user_host() {
Marc Cornellà's avatar
Marc Cornellà committed
17
  local me
Andrew Vit's avatar
Andrew Vit committed
18
19
20
21
22
23
24
25
26
27
28
29
30
  if [[ -n $SSH_CONNECTION ]]; then
    me="%n@%m"
  elif [[ $LOGNAME != $USER ]]; then
    me="%n"
  fi
  if [[ -n $me ]]; then
    echo "%{$fg[cyan]%}$me%{$reset_color%}:"
  fi
}

# Determine the time since last commit. If branch is clean,
# use a neutral color, otherwise colors will vary according to time.
function _git_time_since_commit() {
Marc Cornellà's avatar
Marc Cornellà committed
31
  local last_commit now seconds_since_last_commit
32
  local minutes hours days years commit_age
Marc Cornellà's avatar
Marc Cornellà committed
33
  # Only proceed if there is actually a commit.
34
  if last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null); then
35
36
37
38
39
    now=$(date +%s)
    seconds_since_last_commit=$((now-last_commit))

    # Totals
    minutes=$((seconds_since_last_commit / 60))
40
41
42
43
44
45
46
47
    hours=$((minutes / 60))
    days=$((hours / 24))
    years=$((days / 365))

    if [[ $years -gt 0 ]]; then
      commit_age="${years}y$((days % 365 ))d"
    elif [[ $days -gt 0 ]]; then
      commit_age="${days}d$((hours % 24))h"
Marc Cornellà's avatar
Marc Cornellà committed
48
    elif [[ $hours -gt 0 ]]; then
49
      commit_age+="${hours}h$(( minutes % 60 ))m"
50
51
    else
      commit_age="${minutes}m"
Andrew Vit's avatar
Andrew Vit committed
52
    fi
53

Marc Cornellà's avatar
Marc Cornellà committed
54
    echo "${ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL}${commit_age}%{$reset_color%}"
Andrew Vit's avatar
Andrew Vit committed
55
56
57
58
59
  fi
}

MODE_INDICATOR="%{$fg_bold[yellow]%}❮%{$reset_color%}%{$fg[yellow]%}❮❮%{$reset_color%}"

60
# Git prompt settings
Andrew Vit's avatar
Andrew Vit committed
61
62
63
64
65
66
67
68
69
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[green]%}✔%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%}✚ "
ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[yellow]%}⚑ "
ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%}✖ "
ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%}▴ "
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[cyan]%}§ "
70
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[white]%}◒ "
Andrew Vit's avatar
Andrew Vit committed
71

72
73
74
75
# Ruby prompt settings
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[grey]%}"
ZSH_THEME_RUBY_PROMPT_SUFFIX="%{$reset_color%}"

Andrew Vit's avatar
Andrew Vit committed
76
77
78
79
# Colors vary depending on time lapsed.
ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
80
ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[white]%}"
Andrew Vit's avatar
Andrew Vit committed
81

Janosch Schwalm's avatar
Janosch Schwalm committed
82
# LS colors, made with https://geoff.greer.fm/lscolors/
Andrew Vit's avatar
Andrew Vit committed
83
84
85
export LSCOLORS="exfxcxdxbxegedabagacad"
export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:'
export GREP_COLOR='1;33'