]> git.alrj.org Git - zsh.d.git/blob - S90_prompt
4ecb0799dca2cce41815b789e269ec63afcc1db2
[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 # The difference is that $get_exitcode is set to a command name which should be 
10 # called. There's a layer of indirection.
11
12 get_exitcode=true
13
14 function accept-line-or-clear-warning () {
15   if [[ -z $BUFFER ]]; then
16     get_exitcode=true
17   else
18     get_exitcode=parse_exitcode
19   fi
20   zle accept-line
21 }
22 zle -N accept-line-or-clear-warning
23 bindkey '^M' accept-line-or-clear-warning
24
25
26 setprompt()
27 {
28   # This function sets the entire prompt.
29   # It requires that prompt_subst is set.
30   
31   _username="${C_BYELLOW}%n${C_NO}"
32   _machine="${C_BRED}%m${C_NO}"
33
34   # Git status in the pwd, if applicable
35   if [[ -n ${__ZSH_GIT_BASEDIR} ]]; then
36     _basedir="${C_GREEN}%20<..<${__ZSH_GIT_BASEDIR}%<<${C_NO}"
37     _branch="${C_MAGENTA}@%20>..>${__ZSH_GIT_BRANCH}%>>${__ZSH_GIT_ACTION}${C_NO}"
38     _status="${__ZSH_GIT_STATUS}"
39     _subdir="${C_GREEN}/%15<..<${__ZSH_GIT_SUBDIR}%<<${C_NO}"
40     _path="${_basedir}${_branch}${_status}${_subdir}"
41   else
42     _path="${C_GREEN}%25<..<%~%<<${C_NO}"
43   fi
44   
45   # Virtualenv activated ?
46   if [[ -n ${__ZSH_VIRTUAL_ENV_NAME} ]]; then
47     _venvname="${C_BCYAN}(${__ZSH_VIRTUAL_ENV_NAME})${C_NO}"
48   else
49     _venvname=""
50   fi
51   
52   echo ${_venvname}${_username}@${_machine}:${_path}
53 }
54
55
56 #
57 # Now, the prompt itself
58 #
59 PROMPT='$($get_exitcode)$(setprompt)$ '
60 # RPROMPT='$(battery_level)'