# # Prompt config # setopt prompt_subst # enable colors autoload colors zsh/terminfo if [ "$terminfo[colors]" -ge 8 ]; then colors fi for color in RED GREEN YELLOW BLUE MAGENTA CYAN ORANGE WHITE; do eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}' eval PR_LIGHT_$color='%{$fg[${(L)color}]%}' done PR_NO_COLOR="%{$terminfo[sgr0]%}" export PR_OS_NAME=$(uname -s) if [ -f /etc/debian_version ]; then if which lsb_release >/dev/null 2>&1 ; then PR_OS_NAME="${PR_BLUE}$(lsb_release -is)${PR_WHITE}/${PR_BLUE}$(lsb_release -cs)" fi if [ -f /etc/debian_chroot ]; then PR_OS_NAME="${PR_RED}chroot${PR_WHITE}(${PR_OS_NAME}${PR_WHITE} ${PR_MAGENTA}$(uname -m)${PR_WHITE})" fi fi if [ -n "${SSH_CLIENT}" ]; then export PR_OS_SSH=" via ${PR_LIGHT_RED}ssh" else export PR_OS_SSH= fi pr_battery_level() { if command -v acpi >/dev/null 2>&1 ; then acpi --battery 2>/dev/null | sed -r 's/^Battery .*, ([0-9]*)%.*$/\1/' fi } pr_battery() { local battery_level= local level=$(pr_battery_level) if [ -n "$level" ] ; then if [ "$level" -gt 60 ] ; then local bat_color="${PR_GREEN}" elif [ "$level" -gt 25 ] ; then local bat_color="${PR_YELLOW}" else local bat_color="${PR_RED}" fi battery_level="${PR_WHITE}⌁${bat_color}${level}${PR_WHITE}%%" fi echo -n "${battery_level}" } pr_git_branch() { if command -v git >/dev/null 2>&1 ; then git branch 2>/dev/null | sed -n 's/^\* //p' fi } pr_git_prompt() { local git_prompt= local branch=$(pr_git_branch) if [ -n "$branch" ] ; then local modified=$(git diff --name-only | wc -l) local cached=$(git diff --cached --name-only | wc -l) git_prompt="${PR_YELLOW}${branch}${PR_NO_COLOR}" if [ "$modified" -gt 0 ]; then git_prompt="${git_prompt} ${PR_RED}${modified}${PR_NO_COLOR}±" fi if [ "$cached" -gt 0 ]; then git_prompt="${git_prompt} ${PR_LIGHT_GREEN}${cached}${PR_NO_COLOR}±" fi local commits=$(git rev-list --no-merges --count origin/${branch}..${branch} 2>/dev/null) if [ "$commits" -gt 0 ]; then git_prompt="${git_prompt} ${PR_MAGENTA}${commits}${PR_NO_COLOR}↑" fi git_prompt="${PR_WHITE} on ${git_prompt}" fi echo -n "${git_prompt}" } pr_update_tmux_env() { if [ -n "$TMUX" ] && command -v tmux >/dev/null 2>&1 ; then source <(tmux show-environment | sed -r -e '/^-/d' -e 's/^([^=]+)=(.*)$/\1="\2"/') fi } preexec() { case "$TERM" in xterm*|screen*) # get the command basename local cmd=${1##*\/} if [ -n "${SSH_CLIENT}" ]; then cmd="%n@%M: ${cmd}" fi if [ -n "$TMUX" ]; then print -Pn "\033k\033\134\033k${cmd}\033\134" else print -Pn "\e]0;${cmd}\a" fi ;; esac pr_update_tmux_env } precmd() { case "$TERM" in xterm*|screen*) local cmd="%~" if [ -n "${SSH_CLIENT}" ]; then cmd="%n@%M: ${cmd}" fi if [ -n "$TMUX" ]; then print -Pn "\ek%-3 ${cmd}\e" else print -Pn "\e]0;${cmd}\a" fi ;; esac } myprompt() { if [ "$TERM" = "dumb" ]; then PROMPT="-(%n@%m)-(%(!.%d.%~))->" else PROMPT='\ %(!.${PR_RED}%n.${PR_LIGHT_GREEN}%n)\ ${PR_WHITE} at \ ${PR_MAGENTA}%m\ ${PR_WHITE}${PR_OS_SSH}\ ${PR_WHITE} in \ ${PR_GREEN}%(!.%d.%~)\ $(pr_git_prompt)\ %1(j.${PR_WHITE} with ${PR_LIGHT_GREEN}%j${PR_WHITE} jobs.)\ ${PR_WHITE} using ${PR_OS_NAME} %0(?..${PR_RED}%?)\ %(!.${PR_LIGHT_RED}.${PR_LIGHT_CYAN})>${PR_NO_COLOR}' RPROMPT='$(pr_battery)' fi } myprompt