removed files
[~madcoder/dotfiles.git] / config / zsh / 60_prompt
1 #! /bin/zsh
2
3 autoload colors && colors
4
5 precmd() {
6     local git_dir branch
7
8     psvar=()
9     git_dir=$(git rev-parse --git-dir 2> /dev/null) || return
10     if test -d "$git_dir/rebase-apply"; then
11         if test -f "$git_dir/rebase-apply/rebasing"; then
12             psvar[3]="rebase"
13         elif test -f "$git_dir/rebase-apply/applying"; then
14             psvar[3]="am"
15         else
16             psvar[3]="am/rebase"
17         fi
18         branch="$(git symbolic-ref HEAD 2>/dev/null)"
19     elif test -f "$git_dir/rebase-merge/interactive"; then
20         psvar[3]="rebase -i"
21         branch="$(cat "$git_dir/rebase-merge/head-name")"
22     elif test -d "$git_dir/rebase-merge"; then
23         psvar[3]="rebase -m"
24         branch="$(cat "$git_dir/rebase-merge/head-name")"
25     elif test -f "$git_dir/MERGE_HEAD"; then
26         psvar[3]="merge"
27         branch="$(git symbolic-ref HEAD 2>/dev/null)"
28     else
29         test -f "$git_dir/BISECT_LOG" && psvar[3]="bisect"
30         branch="$(git symbolic-ref HEAD 2>/dev/null)" || \
31             branch="$(git describe --exact-match HEAD 2>/dev/null)" || \
32             branch="$(cut -c1-7 "$git_dir/HEAD")..."
33     fi
34
35     psvar[1]="${$(greadlink -m "$(git rev-parse --show-cdup)./")/$HOME/~}"
36     psvar[2]="${branch#refs/heads/}"
37 }
38
39 _mad_prompt_setup() {
40     local rst
41     local -a pcc
42
43     rst="%{$reset_color%}"
44     pcc[1]="%{$reset_color${1:-$fg_no_bold[green]}%}"
45     pcc[2]="%{$reset_color${2:-$fg_no_bold[yellow]}%}"
46     pcc[3]="%{$reset_color${3:-$fg_no_bold[cyan]}%}"
47     pcc[4]="%{$reset_color${4:-$fg_bold[red]}%}"
48
49 #%{$'\e[s\e[A\e[4Dblah\e[u'$reset_color%}
50 #%{$'\e[400C\e[20D'%}"────────────────────
51     PROMPT="\
52 $pcc[1]┌─(%B%T$pcc[1])──%(1v.<$pcc[3]%1v %B%U%2v%u%(3v.$pcc[4] <%3v>.)$pcc[1]>.)──
53 $pcc[1]└[$pcc[2]%{%(?..%S)%}%m%s$pcc[1]] $rst"
54     RPROMPT="$pcc[1](%B%~$pcc[1])$rst"
55     POSTEDIT=$reset_color
56 }
57
58 if [ $UID -eq 0 ]; then
59     PROMPT="%{$reset_color$fg_bold[yellow]%}[%{$fg_bold[red]%}%n %m%{$fg_bold[yellow]%}]%{$reset_color%} "
60     RPROMPT="%{$reset_color$fg_no_bold[red]%}(%{$fg_bold[red]%}%~%{$fg_no_bold[red]%})%{$reset_color%} "
61 else
62     _mad_prompt_setup
63 fi
64
65 case "$TERM" in
66     xterm|rxvt-unicode)
67         PROMPT="${PROMPT}%{\e]2;zsh\a%}"
68
69         preexec () {
70             local CMD=${1[(wr)^(*=*|sudo|exec|-*)]}
71             echo -ne "\e]2;$CMD\007"
72         }
73     ;;
74     *);;
75 esac