Mercurial > dotfiles
annotate .shell.d/99.prompt.zsh @ 526:852565046ed0 default tip
zsh: fidget with screen/tmux message
This should speed things up very slightly by avoiding some `grep` action
in the common case of no detached screens/tmuxes.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Mon, 14 Nov 2022 11:02:35 -0500 |
parents | 7e8603e0a822 |
children |
rev | line source |
---|---|
0 | 1 # Magic prompt with colors |
2 # username in blue if not root | |
3 # username in red if root - time in pink w/ | |
4 # DANGER replacing the date | |
5 # failed jobs print exit status in the RPS1 with yellow text | |
6 setopt prompt_subst | |
7 | |
8 preexec () { | |
179 | 9 currJob="`echo $3 | cut -d ' ' -f 1 | head -n 1`" |
10 if [[ "$TERM" == "screen" ]]; then | |
11 hostUser="%10<...<%~%<<" | |
12 print -Pn "\ek[$hostUser $currJob]\e\\" | |
13 else | |
14 if [[ "$FANCYTYPE" == "YES" ]]; then | |
15 hostUser="%n@%m: %2~" | |
16 print -Pn "\e]0;$hostUser [$currJob]\a" | |
17 fi | |
18 fi | |
0 | 19 } |
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 | 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 | 25 branch=`vcs_current_branch` |
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 | 28 fi |
29 } | |
30 | |
514
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
31 function _init_async() { |
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
32 async |
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
33 async_stop_worker 'durin42_prompt' || true |
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
34 async_start_worker durin42_prompt -u -n |
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
35 async_register_callback durin42_prompt right_prompt_results |
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
36 } |
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
37 |
382
491cd0cedeee
prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents:
380
diff
changeset
|
38 function right_prompt_results() { |
491cd0cedeee
prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents:
380
diff
changeset
|
39 if [ $2 = 0 ] ; then |
491cd0cedeee
prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents:
380
diff
changeset
|
40 rps_branch=$3 |
491cd0cedeee
prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents:
380
diff
changeset
|
41 zle && zle reset-prompt |
514
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
42 else |
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
43 _init_async |
382
491cd0cedeee
prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents:
380
diff
changeset
|
44 fi |
0 | 45 } |
46 | |
47 if [ "x`whoami`" = "xroot" ] ; then | |
179 | 48 PS1=$'%{\e];%n@%m: %2~ [zsh]\a%}[%m:%3~] %{\e[31m%}%n%{\e[0m%}%# ' |
49 if [[ "$TERM" == "screen" ]] ; then | |
50 PS1=$'%{\ek[%2~ zsh]\e\\%}[%m:%3~] %{\e[31m%}%n%{\e[0m%}%# ' | |
51 fi | |
52 RPS1=$'%{\e[1;35m%}[DANGER %t]%{\e[0m%}%(?..%{\e[1;33m%} %?%{\e[1;0m%})' | |
0 | 53 else |
179 | 54 PS1=$'%{\e];%n@%m: %2~ [zsh]\a%}[%m:%3~] %{\e[34m%}%n%{\e[0m%}%# ' |
55 if [[ "$TERM" == "screen" ]]; then | |
56 PS1=$'%{\ek[%2~ zsh]\e\\%}[%m:%3~] %{\e[34m%}%n%{\e[0m%}%# ' | |
57 fi | |
0 | 58 RPS1=$'[$rps_branch]%(?..%{\e[1;33m%} %?%{\e[0m%})' |
59 fi | |
60 | |
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
|
61 |
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 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
|
63 |
272
02b635053e8f
zsh prompt: allow fancy prompt mode on xterm-256color as well
Augie Fackler <durin42@gmail.com>
parents:
182
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 |
da329720ff18
zsh prompt: add urxvt to whitelisted terms, use a loop instead of many ifs
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
70 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
|
71 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
|
72 RPS1=$'[%W %t]' |
0 | 73 fi |
74 | |
182
e189dfb33bfa
zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents:
179
diff
changeset
|
75 if [[ $TERM == "dumb" ]]; then # in emacs |
e189dfb33bfa
zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents:
179
diff
changeset
|
76 # 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
|
77 # http://www.emacswiki.org/emacs/TrampMode |
e189dfb33bfa
zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents:
179
diff
changeset
|
78 unsetopt zle |
e189dfb33bfa
zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents:
179
diff
changeset
|
79 unsetopt prompt_cr |
e189dfb33bfa
zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents:
179
diff
changeset
|
80 unsetopt prompt_subst |
e189dfb33bfa
zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents:
179
diff
changeset
|
81 unfunction preexec |
389
2dd040318107
prompt: simplify prompt more when tramp is probably in use
Augie Fackler <raf@durin42.com>
parents:
382
diff
changeset
|
82 PS1='$ ' |
2dd040318107
prompt: simplify prompt more when tramp is probably in use
Augie Fackler <raf@durin42.com>
parents:
382
diff
changeset
|
83 RPS1='' |
382
491cd0cedeee
prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents:
380
diff
changeset
|
84 else |
514
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
85 autoload -Uz async |
7e8603e0a822
zsh: properly set up zsh async stuff
Augie Fackler <raf@durin42.com>
parents:
389
diff
changeset
|
86 _init_async |
382
491cd0cedeee
prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents:
380
diff
changeset
|
87 function precmd () { |
491cd0cedeee
prompt: use async.zsh to avoid weird disowned process jank
Augie Fackler <raf@durin42.com>
parents:
380
diff
changeset
|
88 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
|
89 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
|
90 } |
182
e189dfb33bfa
zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents:
179
diff
changeset
|
91 fi |
e189dfb33bfa
zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents:
179
diff
changeset
|
92 |
e189dfb33bfa
zsh prompt: unset basically everything if in tramp
Augie Fackler <durin42@gmail.com>
parents:
179
diff
changeset
|
93 |
0 | 94 #nonfancy no-frills prompt - disabled (same as the "non-fancy" one above) |
95 #prompt='[%m:%3~] %n%# ' | |
96 #RPS1=$'[%W %t]' |