Skip to content

Instantly share code, notes, and snippets.

@freemo
Last active February 27, 2022 15:45
Show Gist options
  • Save freemo/728d124a18b7de32d241 to your computer and use it in GitHub Desktop.
Save freemo/728d124a18b7de32d241 to your computer and use it in GitHub Desktop.
Customized ZSH prompt
# place this at ~/.zshrc
setfont sun12x22
zstyle ':completion:*' completer _complete _ignored
zstyle :compinstall filename '/home/freemo/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
unsetopt autocd
bindkey -e
# End of lines configured by zsh-newuser-install
setopt promptsubst
setopt prompt_subst
autoload -Uz promptinit
promptinit
prompt freemo
# freemo prompt theme
#place this at /usr/share/zsh/functions/Prompts/prompt_freemo_setup
# must add the following line to .zshrc: setopt prompt_subst
prompt_freemo_help () {
cat <<'EOF'
prompt freemo [<color1> [<color2> [<color3> [<color4> [<color5>]]]]]
defaults are red, cyan, green, yellow, and white, respectively.
EOF
}
prompt_freemo_setup () {
local -a pcc
local -A pc
local p_date p_tty p_plat p_ver p_userpwd p_apm p_shlvlhist p_rc p_end p_win
autoload -Uz vcs_info
pcc[1]=${1:-${${SSH_CLIENT+'yellow'}:-'red'}}
pcc[2]=${2:-'cyan'}
pcc[3]=${3:-'green'}
pcc[4]=${4:-'yellow'}
pcc[5]=${5:-'white'}
pc['\[']="%F{$pcc[1]}["
pc['\]']="%F{$pcc[1]}]"
pc['<']="%F{$pcc[1]}<"
pc['>']="%F{$pcc[1]}>"
pc['\(']="%F{$pcc[1]}("
pc['\)']="%F{$pcc[1]})"
zstyle ':vcs_info:*' actionformats "%F{red}(%F{green}%s%F{red}:%F{yellow}%r%F{red})-[%F{cyan}%b%F{red}|%F{cyan}%a%F{red}]-[%F{cyan}%u%c%F{red}]%f %m"
zstyle ':vcs_info:*' formats "%F{red}(%F{green}%s%F{red}:%F{yellow}%r%F{red})-[%F{cyan}%b%F{red}]-[%F{cyan}%u%c%F{red}]%f %m"
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' enable cvs svn git hg bzr cdv darcs fossil mtn p4 svk tla
p_date="$pc['\[']%F{$pcc[2]}%D{%a %m/%d/%y %R %Z}$pc['\]']"
# p_plat="$pc['\[']%F{$pcc[2]}${MACHTYPE}/${OSTYPE}/$(uname -r)$pc['\]']"
p_plat="$pc['\[']%F{$pcc[2]}$(uname -r)$pc['\]']"
p_job="$pc['\[']%F{$pcc[5]}%F{$pcc[2]}%j%F{$pcc[5]} jobs$pc['\]']"
# p_ver="$pc['\[']%F{$pcc[5]}${ZSH_VERSION}$pc['\]']"
p_load="$pc['\[']%F{$pcc[5]}load%F{$pcc[1]}:%F{$pcc[2]}%2v%f$pc['\]']"
p_mem="$pc['\[']%F{$pcc[5]}Memory%F{$pcc[1]}:%F{$pcc[2]}%3v%%%f$pc['\]']"
p_bat="$pc['\[']%F{$pcc[5]}Battery%F{$pcc[1]}:%F{$pcc[2]}%4v%f$pc['\]']"
p_tty="$pc['\[']%F{$pcc[3]}%y$pc['\]']"
[[ -n "$WINDOW" ]] && p_win="$pc['\(']%F{$pcc[4]}$WINDOW$pc['\)']"
p_userpwd="$pc['<']%F{$pcc[3]}%n@%m$p_win$p_tty%F{$pcc[1]}:%F{$pcc[4]}%~$pc['>']"
p_vcs='${vcs_info_msg_0_}'
p_shlvlhist="%fzsh%(2L./$SHLVL.) %B%h%b "
p_rc="%(?..$pc['\[']%K{red}%F{$pcc[5]}error %F{$pcc[2]}%?%1v%k$pc['\]'] )"
p_end="%f%B%(!.%K{red}#%k.%%)%b "
zle_highlight[(r)default:*]=default:$pcc[2]
prompt="
$p_job$p_load$p_mem$p_bat$p_plat$p_date
$p_userpwd $p_vcs
$p_shlvlhist$p_rc$p_end"
PS2='%(4_.\.)%3_> %E'
add-zsh-hook precmd prompt_freemo_precmd
}
prompt_freemo_precmd () {
setopt noxtrace noksharrays localoptions
local exitstatus=$?
local git_dir git_ref
psvar=()
[[ $exitstatus -ge 128 ]] && psvar[1]=" $signals[$exitstatus-127]" ||
psvar[1]=""
[[ -o interactive ]] && jobs -l
vcs_info
psvar[2]=`cat /proc/loadavg| sed 's/\([0-9.]* [0-9.]* [0-9.]*\).*/\1/'`
memfree=`grep MemFree /proc/meminfo | awk '{print $2}'`
memtotal=`grep MemTotal /proc/meminfo | awk '{print $2}'`
declare -i memperc
(( memperc = ( $memfree * 100.0 ) / $memtotal ))
psvar[3]="$memperc"
psvar[4]=`upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep percentage | awk '{print $2}'`
}
prompt_freemo_setup "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment