#! /usr/bin/zsh # # Exit code. # # Hide exit code after a blank line. # Inspired from https://github.com/robbyrussell/oh-my-zsh/blob/66b7fe1b27637feba61a4b47e113b18b69432bf2/themes/dieter.zsh-theme # The difference is that $get_exitcode is set to a command name which should be # called. There's a layer of indirection. 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}@%20>..>${__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 # Virtualenv activated ? if [[ -n ${__ZSH_VIRTUAL_ENV_NAME} ]]; then _venvname="${C_BCYAN}(${__ZSH_VIRTUAL_ENV_NAME})${C_NO}" else _venvname="" fi echo ${_venvname}${_username}@${_machine}:${_path} } # # Now, the prompt itself # PROMPT='$($get_exitcode)$(setprompt)$ ' # RPROMPT='$(battery_level)'