Skip to content

Instantly share code, notes, and snippets.

@Ailrun
Last active February 16, 2020 14:54
Show Gist options
  • Save Ailrun/66350f411114f84e42874700399db1f2 to your computer and use it in GitHub Desktop.
Save Ailrun/66350f411114f84e42874700399db1f2 to your computer and use it in GitHub Desktop.
ailrun.zsh-theme
#!/usr/bin/env zsh
# Ailrun ZSH Theme
local -r default_PS1='${_user_host}${_current_dir} $(git_prompt_info)
%{$fg[${_caret_color}]%}%(!.!.>)%{$resetcolor%} '
local -r default_PS2='%{$fg[${_caret_color}]%}%(!.!.>)...%{$reset_color%} '
local -r default_RPS1='$(_git_time_since_commit) $(git_prompt_status) ${_return_status}'
if [[ -z "${INSIDE_EMACS}" ]]; then
PS1="${default_PS1}"
PS2="${default_PS2}"
RPS1="${default_RPS1}"
else
# Emacs does not support colors well
PS1='%~%(!.!.>) '
PS2='%(!.!.>)... '
fi
local _caret_color="white"
local -r _current_dir="%{$fg_bold[cyan]%}%~%{$reset_color%}"
local -r _return_status="%{$fg_bold[red]%}%(?..%?)%{$reset_color%}"
local -r _user_host="%{$fg[blue]%}%n%{$fg[green]%}:%{$reset_color%}"
# 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() {
# Only proceed if there is actually a commit.
if last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null); then
now=$(date +%s)
seconds_since_last_commit=$((now-last_commit))
# Totals
minutes=$((seconds_since_last_commit / 60))
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
commit_age="${days}d"
elif [[ $minutes -gt 60 ]]; then
commit_age="${sub_hours}h${sub_minutes}m"
else
commit_age="${minutes}m"
fi
echo "%{$fg[white]%}$commit_age%{$reset_color%}"
fi
}
if [[ "${USER}" == "root" ]]; then
_caret_color="yellow"
fi
MODE_INDICATOR="%{$fg_bold[yellow]%}<%{$reset_color%}%{$fg[yellow]%}<<%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}"
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]%}(+)%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[yellow]%}(!)%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%}(-)%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%}(^)%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[cyan]%}($)%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[white]%}(?)%{$reset_color%}"
# LS colors, made with https://geoff.greer.fm/lscolors/
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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment