Skip to content

Instantly share code, notes, and snippets.

@Namorzyny
Last active September 18, 2020 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Namorzyny/c15c84ea85cbb23098da17ec8322d846 to your computer and use it in GitHub Desktop.
Save Namorzyny/c15c84ea85cbb23098da17ec8322d846 to your computer and use it in GitHub Desktop.
A modified ys.zsh-theme https://gist.github.com/ysmood/6110461
# 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 2013 Yad Smood
# Sep 2020 Namorzyny
# VCS
YS_KAI_VCS_PROMPT_PREFIX1=" %{$fg[white]%}on%{$reset_color%} "
YS_KAI_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}"
YS_KAI_VCS_PROMPT_SUFFIX="%{$reset_color%}"
YS_KAI_VCS_PROMPT_DIRTY=" %{$fg[red]%}x"
YS_KAI_VCS_PROMPT_CLEAN=" %{$fg[green]%}o"
# Git info
local git_info='$(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="${YS_KAI_VCS_PROMPT_PREFIX1}git${YS_KAI_VCS_PROMPT_PREFIX2}"
ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_KAI_VCS_PROMPT_SUFFIX"
ZSH_THEME_GIT_PROMPT_DIRTY="$YS_KAI_VCS_PROMPT_DIRTY"
ZSH_THEME_GIT_PROMPT_CLEAN="$YS_KAI_VCS_PROMPT_CLEAN"
# HG info
local hg_info='$(ys_kai_hg_prompt_info)'
ys_kai_hg_prompt_info() {
# make sure this is a hg dir
if [ -d '.hg' ]; then
echo -n "${YS_KAI_VCS_PROMPT_PREFIX1}hg${YS_KAI_VCS_PROMPT_PREFIX2}"
echo -n $(hg branch 2>/dev/null)
if [ -n "$(hg status 2>/dev/null)" ]; then
echo -n "$YS_KAI_VCS_PROMPT_DIRTY"
else
echo -n "$YS_KAI_VCS_PROMPT_CLEAN"
fi
echo -n "$YS_KAI_VCS_PROMPT_SUFFIX"
fi
}
preexec() {
command_start_timestamp=$[$(date +%s%N)/1000000]
}
precmd() {
if [ "${command_start_timestamp}" = '' ]; then
command_duration=''
return
fi
command_stop_timestamp=$[$(date +%s%N)/1000000]
command_duration=$[${command_stop_timestamp}-${command_start_timestamp}]
command_start_timestamp=''
}
local execution_duration='$(get_execution_duration)'
get_execution_duration() {
if [ "${command_duration}" = '' ]; then
return
fi
local hours=$[${command_duration}/3600000]
local minutes=$[(${command_duration}%3600000)/60000]
local seconds=$[${command_duration}%60000/1000]
local milliseconds=$[${command_duration}%1000]
echo -n " %{$terminfo[bold]$fg[magenta]%}"
if [ $hours -gt 0 ]; then
echo -n "${hours}h"
fi
if [ $minutes -gt 0 ]; then
echo -n "${minutes}m"
fi
if [ $seconds -gt 0 ]; then
echo -n "${seconds}s"
fi
if [ ${command_duration} -lt 1000 ]; then
echo -n "${milliseconds}ms"
fi
echo -n "%{$reset_color%}"
}
local exit_code="%(?,,%{$terminfo[bold]$fg[red]%}[%?]%{$reset_color%})"
# Prompt format:
#
# PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME DURATION] [LAST_EXIT_CODE]
# $ COMMAND
#
# For example:
#
# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42 42ms] [1]
# $
PROMPT="
%{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \
%(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n) \
%{$fg[white]%}@ \
%{$fg[green]%}%m \
%{$fg[white]%}in \
%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
${hg_info}\
${git_info}\
%{$reset_color%} [%*${execution_duration}] $exit_code
%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment