annotate .shell.d/99.prompt.zsh @ 424:7a8483897360

custom: reformat custom-safe-themes
author Augie Fackler <raf@durin42.com>
date Tue, 29 Nov 2016 13:26:10 -0500
parents 2dd040318107
children 7e8603e0a822
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 # Magic prompt with colors
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 # username in blue if not root
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 # username in red if root - time in pink w/
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4 # DANGER replacing the date
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 # failed jobs print exit status in the RPS1 with yellow text
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6 setopt prompt_subst
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 preexec () {
179
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
9 currJob="`echo $3 | cut -d ' ' -f 1 | head -n 1`"
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
10 if [[ "$TERM" == "screen" ]]; then
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
11 hostUser="%10<...<%~%<<"
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
12 print -Pn "\ek[$hostUser $currJob]\e\\"
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
13 else
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
14 if [[ "$FANCYTYPE" == "YES" ]]; then
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
15 hostUser="%n@%m: %2~"
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
16 print -Pn "\e]0;$hostUser [$currJob]\a"
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
17 fi
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
18 fi
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 }
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20
380
0ceb8554801e zsh: make vcs info in prompt async
Augie Fackler <raf@durin42.com>
parents: 272
diff changeset
21 PROMPT_TMP="${HOME}/.augie-zsh-tmp-prompt"
0ceb8554801e zsh: make vcs info in prompt async
Augie Fackler <raf@durin42.com>
parents: 272
diff changeset
22
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 function right_side_prompt() {
382
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
24 cd $1
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 branch=`vcs_current_branch`
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 if [ $? = 0 ] ; then
382
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
27 print $branch
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 }
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30
382
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
31 function right_prompt_results() {
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
32 if [ $2 = 0 ] ; then
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
33 rps_branch=$3
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
34 zle && zle reset-prompt
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
35 fi
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 }
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38 if [ "x`whoami`" = "xroot" ] ; then
179
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
39 PS1=$'%{\e];%n@%m: %2~ [zsh]\a%}[%m:%3~] %{\e[31m%}%n%{\e[0m%}%# '
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
40 if [[ "$TERM" == "screen" ]] ; then
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
41 PS1=$'%{\ek[%2~ zsh]\e\\%}[%m:%3~] %{\e[31m%}%n%{\e[0m%}%# '
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
42 fi
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
43 RPS1=$'%{\e[1;35m%}[DANGER %t]%{\e[0m%}%(?..%{\e[1;33m%} %?%{\e[1;0m%})'
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
44 else
179
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
45 PS1=$'%{\e];%n@%m: %2~ [zsh]\a%}[%m:%3~] %{\e[34m%}%n%{\e[0m%}%# '
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
46 if [[ "$TERM" == "screen" ]]; then
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
47 PS1=$'%{\ek[%2~ zsh]\e\\%}[%m:%3~] %{\e[34m%}%n%{\e[0m%}%# '
ebbbf3567a0e zsh prompt: detabify
Augie Fackler <durin42@gmail.com>
parents: 178
diff changeset
48 fi
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
49 RPS1=$'[$rps_branch]%(?..%{\e[1;33m%} %?%{\e[0m%})'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
51
178
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
52
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
53 export FANCYTYPE="NO"
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
54
272
02b635053e8f zsh prompt: allow fancy prompt mode on xterm-256color as well
Augie Fackler <durin42@gmail.com>
parents: 182
diff changeset
55 for ok in rxvt rxvt-unicode xterm xterm-256color xterm-color screen ; do
178
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
56 if [ "$TERM" = "$ok" ] ; then
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
57 export FANCYTYPE="YES"
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
58 fi
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
59 done
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
60
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
61 if [ $FANCYTYPE = "NO" ] ; then
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
62 prompt='[%m:%3~] %n%# '
da329720ff18 zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
63 RPS1=$'[%W %t]'
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64 fi
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65
182
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
66 if [[ $TERM == "dumb" ]]; then # in emacs
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
67 # for tramp to not hang, need the following. cf:
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
68 # http://www.emacswiki.org/emacs/TrampMode
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
69 unsetopt zle
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
70 unsetopt prompt_cr
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
71 unsetopt prompt_subst
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
72 unfunction preexec
389
2dd040318107 prompt: simplify prompt more when tramp is probably in use
Augie Fackler <raf@durin42.com>
parents: 382
diff changeset
73 PS1='$ '
2dd040318107 prompt: simplify prompt more when tramp is probably in use
Augie Fackler <raf@durin42.com>
parents: 382
diff changeset
74 RPS1=''
382
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
75 else
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
76 autoload -Uz async && async
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
77 async_start_worker durin42_prompt -u -n
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
78 async_register_callback durin42_prompt right_prompt_results
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
79
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
80 function precmd () {
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
81 rps_branch="$(date '+%D %H:%M')"
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
82 async_job durin42_prompt right_side_prompt $PWD
491cd0cedeee prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents: 380
diff changeset
83 }
182
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
84 fi
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
85
e189dfb33bfa zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents: 179
diff changeset
86
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 #nonfancy no-frills prompt - disabled (same as the "non-fancy" one above)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 #prompt='[%m:%3~] %n%# '
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 #RPS1=$'[%W %t]'