Skip to content

Instantly share code, notes, and snippets.

@jezek
Last active June 16, 2021 13:34
Show Gist options
  • Save jezek/3e2b3b9ed350084ccde97f8be8c7a88f to your computer and use it in GitHub Desktop.
Save jezek/3e2b3b9ed350084ccde97f8be8c7a88f to your computer and use it in GitHub Desktop.
# Based on oh-my-zsh gnzh theme
setopt prompt_subst
() {
local PR_USER PR_USER_OP PR_PROMPT PR_HOST
# Check the UID
if [[ $UID -ne 0 ]]; then # normal user
PR_USER='%F{green}%n%f'
PR_USER_OP='%F{green}%#%f'
PR_PROMPT='%f$%f'
else # root
PR_USER='%F{red}%n%f'
PR_USER_OP='%F{red}%#%f'
PR_PROMPT='%F{red}#%f'
fi
# Check if we are on SSH or not
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then
PR_HOST='%F{red}%M%f' # SSH
else
PR_HOST='%F{green}%M%f' # no SSH
fi
#local return_code_string=$(print -P "$return_code")
#local return_code_len=${#${return_code_string}}
#local time=`date +"[%H:%M:%S]"`
#local time_len=${#${time}}
#local spaces=$(($COLUMNS-$time_len-$return_code_len))
#echo $return_code_len","$time_len","$COLUMNS
#local pad=$(printf '%*s' "$spaces")
#pad=${pad// / }
local return_code="%(?..%F{red}%? ↵ %f)"
local return_time="%F{red}%D{[%H:%M:%S]}%f"
local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
local current_dir="%B%F{blue}%~%f%b"
local git_branch='$(git_prompt_info)'
local up=$'\e[1A'
PROMPT="${${up}%}${return_code}
${user_host} ${current_dir} ${git_branch}
$PR_PROMPT "
#RPROMPT="${return_time}"
ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="› %f"
}
jezek_precmd () {
local TIME=`date +"[%H:%M:%S]"`
local TIMELEN=${#${TIME}}
print -P "\033[$(($COLUMNS-$TIMELEN-1))C%F{red}${TIME}%f"
}
jezek_preexec () {
local TIME=`date +"[%H:%M:%S]"`
#local zero='%([BSUbfksu]|([FK]|){*})'
#local prompt="${(S%%)PROMPT//$~zero/}"
#local promptLines=("${(f)prompt}")
#local PROMPTLEN=${#${promptLines[${#promptLines[@]}]}}
#echo "\033[1A\033[$(($(echo -n $1 | wc -m)+$PROMPTLEN))C $fg[blue]${TIME}$reset_color"
local TIMELEN=${#${TIME}}
print -P "\033[1A\033[$(($COLUMNS-$TIMELEN-1))C%F{green}${TIME}%f"
#print -Pn "\033[$(($COLUMNS-$TIMELEN-1))C%F{green}${TIME}%f\033[$(($COLUMNS-1))D"
}
autoload -U add-zsh-hook
add-zsh-hook precmd jezek_precmd
add-zsh-hook preexec jezek_preexec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment