X-Git-Url: https://git.alrj.org/?p=zsh.d.git;a=blobdiff_plain;f=S90_prompt;h=b9a7d4e9bb85d349e2fe92aee747a2e873bd66bb;hp=10832a2d896c751adc9909302a298541197c440c;hb=24e74f7cd9e63583edcc3facf253bf439202319f;hpb=32afa7668c575e962af9dac2bd3586a1db4f5491 diff --git a/S90_prompt b/S90_prompt index 10832a2..b9a7d4e 100644 --- a/S90_prompt +++ b/S90_prompt @@ -1,39 +1,53 @@ #! /usr/bin/zsh -# -# Prepare colors, ignoring length -# -C_NO="%{$reset_color%}" -C_BYELLOW="%{${fg_bold[yellow]}%}" -C_BRED="%{${fg_bold[red]}%}" -C_BCYAN="%{${fg_bold[cyan]}%}" -C_GREEN="%{${fg[green]}%}" -C_BGREEN="%{${fg_bold[green]}%}" -C_MAGENTA="%{${fg_bold[magenta]}%}" - - # -# Prompt parts +# Exit code. # -_username="${C_BYELLOW}%n${C_NO}" -_machine="${C_BRED}%m${C_NO}" -_hour="${C_BCYAN}[%D{%H:%M}]${C_NO}" - -_exitcode="%(?::${C_BRED}[ %1v ]${C_NO} -)$(true)" +# Hide exit code after a blank line. +# Inspired from https://github.com/robbyrussell/oh-my-zsh/blob/66b7fe1b27637feba61a4b47e113b18b69432bf2/themes/dieter.zsh-theme + + +get_exitcode=true + +function accept-line-or-clear-warning () { + if [[ -z $BUFFER ]]; then + get_exitcode=true + else + get_exitcode=parse_exitcode + fi + zle accept-line +} +zle -N accept-line-or-clear-warning +bindkey '^M' accept-line-or-clear-warning + + +setprompt() +{ + # This function sets the entire prompt. + # It requires that prompt_subst is set. + + _username="${C_BYELLOW}%n${C_NO}" + _machine="${C_BRED}%m${C_NO}" + + # Git status in the pwd, if applicable + if [[ -n $__ZSH_GIT_BASEDIR ]]; then + _basedir="${C_GREEN}%20<..<${__ZSH_GIT_BASEDIR}%<<${C_NO}" + _branch="${C_MAGENTA}@${__ZSH_GIT_BRANCH}${__ZSH_GIT_ACTION}${C_NO}" + _status="${__ZSH_GIT_STATUS}" + _subdir="${C_GREEN}/%15<..<${__ZSH_GIT_SUBDIR}%<<${C_NO}" + _path="${_basedir}${_branch}${_status}${_subdir}" + else + _path="${C_GREEN}%25<..<%~%<<${C_NO}" + fi + + + echo ${_username}@${_machine}:${_path} +} -_action="%(5v,%5v%,)" -_path='${C_GREEN}%(7v,%20<..<%7v%<<${C_NO}${C_MAGENTA}@%6v%5v${__ZSH_GIT_STATUS}${C_GREEN}/%15<..<%8v%<<,%25<..<%~%<<)${C_NO}' - - -_batt='%{${fg_bold[$psvar[3]]}%}%2v%{$reset_color%} ' - # # Now, the prompt itself # -#PROMPT="${_exitcode}${_hour} ${_username}@${_machine}:${_vcs}${_path}$ " -PROMPT="${_exitcode}${_username}@${_machine}:${_vcs}${_path}$ " - -RPROMPT="${_batt}" \ No newline at end of file +PROMPT='$($get_exitcode)$(setprompt)$ ' +RPROMPT='$(battery_level)'