]> git.alrj.org Git - zsh.d.git/blob - S90_prompt
Rework the prompt config.
[zsh.d.git] / S90_prompt
1 #! /usr/bin/zsh
2
3
4 #
5 # Exit code.
6 #
7 # Hide exit code after a blank line.
8 # Inspired from https://github.com/robbyrussell/oh-my-zsh/blob/66b7fe1b27637feba61a4b47e113b18b69432bf2/themes/dieter.zsh-theme
9
10
11 get_exitcode=true
12
13 function accept-line-or-clear-warning () {
14   if [[ -z $BUFFER ]]; then
15     get_exitcode=true
16   else
17     get_exitcode=parse_exitcode
18   fi
19   zle accept-line
20 }
21 zle -N accept-line-or-clear-warning
22 bindkey '^M' accept-line-or-clear-warning
23
24
25 setprompt()
26 {
27   # This function sets the entire prompt.
28   # It requires that prompt_subst is set.
29   
30   _username="${C_BYELLOW}%n${C_NO}"
31   _machine="${C_BRED}%m${C_NO}"
32
33   # Git status in the pwd, if applicable
34   if [[ -n $__ZSH_GIT_BASEDIR ]]; then
35     _basedir="${C_GREEN}%20<..<${__ZSH_GIT_BASEDIR}%<<${C_NO}"
36     _branch="${C_MAGENTA}@${__ZSH_GIT_BRANCH}${__ZSH_GIT_ACTION}${C_NO}"
37     _status="${__ZSH_GIT_STATUS}"
38     _subdir="${C_GREEN}/%15<..<${__ZSH_GIT_SUBDIR}%<<${C_NO}"
39     _path="${_basedir}${_branch}${_status}${_subdir}"
40   else
41     _path="${C_GREEN}%25<..<%~%<<${C_NO}"
42   fi
43   
44   
45   echo ${_username}@${_machine}:${_path}
46 }
47
48
49 #
50 # Now, the prompt itself
51 #
52 PROMPT='$($get_exitcode)$(setprompt)$ '
53 RPROMPT='$(battery_level)'