Skip to content

Instantly share code, notes, and snippets.

@krast
Last active April 7, 2020 08:20
Show Gist options
  • Save krast/211e6b4e97c72babe9750ec949db35f5 to your computer and use it in GitHub Desktop.
Save krast/211e6b4e97c72babe9750ec949db35f5 to your computer and use it in GitHub Desktop.
zsh theme
# Clean, simple, compatible and meaningful.
# Tested on Linux, Unix and Windows under ANSI colors.
# It is recommended to use with a dark background.
# Colors: black, red, green, yellow, *blue, magenta, cyan, and white.
#
# Mar 2020 Krast
# E-mail: [email protected]
# logo gnerv
gnerv="$FG[238]
██████╗ ███╗ ██╗███████╗██████╗ ██╗ ██╗
██╔════╝ ████╗ ██║██╔════╝██╔══██╗██║ ██║
██║ ███╗██╔██╗ ██║█████╗ ██████╔╝██║ ██║
██║ ██║██║╚██╗██║██╔══╝ ██╔══██╗╚██╗ ██╔╝
╚██████╔╝██║ ╚████║███████╗██║ ██║ ╚████╔╝
╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═══╝
"
# date time
g_date="$FG[038]⚫ Today is `date`"
# print
print -P $gnerv
print -P $g_date
# krast prompt chat
# -----------------
function krast_prompt_char {
git branch >/dev/null 2>/dev/null && echo '±' && return
hg root >/dev/null 2>/dev/null && echo 'Hg' && return
echo '$'
}
# git
# ---
ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%} [!]"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?"
ZSH_THEME_GIT_PROMPT_CLEAN=""
# 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]%}"
ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
# virtualenv
# ----------
function virtualenv_info {
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') '
}
local exit_code="%(?,%?,%{$fg[red]%}%?%{$reset_color%})"
# Git sometimes goes into a detached head state. git_prompt_info doesn't
# return anything in this case. So wrap it in another function and check
# for an empty string.
function check_git_prompt_info() {
if git rev-parse --git-dir > /dev/null 2>&1; then
if [[ -z $(git_prompt_info) ]]; then
echo "%{$fg[magenta]%}detached-head%{$reset_color%})"
else
echo "$(git_prompt_info)"
fi
fi
}
# Determine if we are using a gemset.
function rvm_gemset() {
if hash rvm 2>/dev/null; then
GEMSET=`rvm gemset list | grep '=>' | cut -b4-`
if [[ -n $GEMSET ]]; then
echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|"
fi
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() {
if git rev-parse --git-dir > /dev/null 2>&1; then
# Only proceed if there is actually a commit.
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
# Get the last commit.
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
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 [[ -n $(git status -s 2> /dev/null) ]]; then
if [ "$MINUTES" -gt 30 ]; then
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
elif [ "$MINUTES" -gt 10 ]; then
COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
fi
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
fi
if [ "$HOURS" -gt 24 ]; then
echo "[$(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}] "
elif [ "$MINUTES" -gt 60 ]; then
echo "[$(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}] "
else
echo "[$(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}] "
fi
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
echo "[$(rvm_gemset)$COLOR~] "
fi
fi
}
IP=$(hostname -I | awk '{print $1}')
# PROMPT
# ------
# Prompt format:
#
# PRIVILEGES USER at MACHINE in DIRECTORY on git:BRANCH STATE [TIME] tty:$TTY L:$SHELL_LEVEL N:LINE_NUM C:LAST_EXIT_CODE
# $ COMMAND
#
# For example:
#
# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] tty:s000 L:1 N:12 C:0
# $
PROMPT='
%{$fg[magenta]%}%n%{$reset_color%} \
at \
%{$fg[yellow]%}%m%{$reset_color%} \
%{$FG[120]%}$IP%{$reset_color%} \
in \
%{$fg_bold[green]%}${PWD/#$HOME/~}%{$reset_color%}$(git_prompt_info) \
$(git_time_since_commit)\
[%*] tty:%l L:%L N:%i C:$exit_code
$(virtualenv_info)$(krast_prompt_char) '
# Clean, simple, compatible and meaningful.
# Tested on Linux, Unix and Windows under ANSI colors.
# It is recommended to use with a dark background.
# Colors: black, red, green, yellow, *blue, magenta, cyan, and white.
#
# Mar 2020 Krast
# E-mail: [email protected]
# Login Info
# -----------
# System load
g_load=`top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{printf "☉ System load : %.1f%", 100-$1 }'`
# Memory Usage
g_memory=`free -m | awk 'NR==2{printf "☉ Memory Usage: %.2f%", $3*100/$2 }'`
# Disk Usage
g_disk=`df -h | awk '$NF=="/"{printf "☉ Disk Usage: %.1f%", $5}'`
# System uptime
g_uptime=`uptime | awk -F'( |,|:)+' '{ if ($7=="min") m=$6; else { if ($7~/^day/) { d=$6; h=$8; m=$9} else {h=$6;m=$7}}}{print "☉ System uptime:",d+0,"days,",h+0,"hours"}'`
# array System information
g_listOfNames=("$g_load" "$g_memory" "$g_disk" "$g_uptime")
# System information
g_information=`
for value in "${g_listOfNames[@]}"; do
printf "%-8s\n" "${value}"
done | column`
# logo gnerv
gnerv='$FG[239]
██████╗ ███╗ ██╗███████╗██████╗ ██╗ ██╗
██╔════╝ ████╗ ██║██╔════╝██╔══██╗██║ ██║
██║ ███╗██╔██╗ ██║█████╗ ██████╔╝██║ ██║
██║ ██║██║╚██╗██║██╔══╝ ██╔══██╗╚██╗ ██╔╝
╚██████╔╝██║ ╚████║███████╗██║ ██║ ╚████╔╝
╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═══╝
$FG[038]🔵 System information ➔$reset_color
'
# date time
g_date="\n$FG[038]⚫ Today is `date`"
# print
print -P $gnerv
echo $g_information
print -P $g_date
# krast prompt chat
# -----------------
function krast_prompt_char {
git branch >/dev/null 2>/dev/null && echo '±' && return
hg root >/dev/null 2>/dev/null && echo 'Hg' && return
echo '$'
}
# git
# ---
ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%} [!]"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?"
ZSH_THEME_GIT_PROMPT_CLEAN=""
# 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]%}"
ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
# virtualenv
# ----------
function virtualenv_info {
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') '
}
local exit_code="%(?,%?,%{$fg[red]%}%?%{$reset_color%})"
# Git sometimes goes into a detached head state. git_prompt_info doesn't
# return anything in this case. So wrap it in another function and check
# for an empty string.
function check_git_prompt_info() {
if git rev-parse --git-dir > /dev/null 2>&1; then
if [[ -z $(git_prompt_info) ]]; then
echo "%{$fg[magenta]%}detached-head%{$reset_color%})"
else
echo "$(git_prompt_info)"
fi
fi
}
# Determine if we are using a gemset.
function rvm_gemset() {
if hash rvm 2>/dev/null; then
GEMSET=`rvm gemset list | grep '=>' | cut -b4-`
if [[ -n $GEMSET ]]; then
echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|"
fi
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() {
if git rev-parse --git-dir > /dev/null 2>&1; then
# Only proceed if there is actually a commit.
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
# Get the last commit.
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
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 [[ -n $(git status -s 2> /dev/null) ]]; then
if [ "$MINUTES" -gt 30 ]; then
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
elif [ "$MINUTES" -gt 10 ]; then
COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
fi
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
fi
if [ "$HOURS" -gt 24 ]; then
echo "[$(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}] "
elif [ "$MINUTES" -gt 60 ]; then
echo "[$(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}] "
else
echo "[$(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}] "
fi
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
echo "[$(rvm_gemset)$COLOR~] "
fi
fi
}
IP=$(hostname -I | awk '{print $1}')
# PROMPT
# ------
# Prompt format:
#
# PRIVILEGES USER at MACHINE in DIRECTORY on git:BRANCH STATE [TIME] tty:$TTY L:$SHELL_LEVEL N:LINE_NUM C:LAST_EXIT_CODE
# $ COMMAND
#
# For example:
#
# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] tty:s000 L:1 N:12 C:0
# $
PROMPT='
%{$fg[magenta]%}%n%{$reset_color%} \
at \
%{$fg[yellow]%}%m%{$reset_color%} \
%{$FG[120]%}$IP%{$reset_color%} \
in \
%{$fg_bold[green]%}${PWD/#$HOME/~}%{$reset_color%}$(git_prompt_info) \
$(git_time_since_commit)\
[%*] tty:%l L:%L N:%i C:$exit_code
$(virtualenv_info)$(krast_prompt_char) '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment