add the functions needed for some keybindings
[zsh.git] / .zsh / functions / setprompt
1 # -*- mode:sh -*-
2
3 ###
4 # See if we can use colors.
5 autoload zsh/terminfo
6
7 # set colors for use in prompts
8 if autoload colors && colors 2>/dev/null ; then
9 for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
10 eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
11 eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
12 (( count = $count + 1 ))
13 done
14 PR_NO_COLOUR="%{$terminfo[sgr0]%}"
15 else
16 PR_BLUE=$'%{\e[1;34m%}'
17 PR_RED=$'%{\e[1;31m%}'
18 PR_GREEN=$'%{\e[1;32m%}'
19 PR_CYAN=$'%{\e[1;36m%}'
20 PR_WHITE=$'%{\e[1;37m%}'
21 PR_MAGENTA=$'%{\e[1;35m%}'
22 PR_YELLOW=$'%{\e[1;33m%}'
23 PR_NO_COLOR=$'%{\e[0m%}'
24 fi
25
26 ###
27 # See if we can use extended characters to look nicer.
28 typeset -A altchar
29 set -A altchar ${(s..)terminfo[acsc]}
30 PR_SET_CHARSET="%{$terminfo[enacs]%}"
31 PR_SHIFT_IN="%{$terminfo[smacs]%}"
32 PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
33 PR_HBAR=${altchar[q]:--}
34 PR_ULCORNER=${altchar[l]:--}
35 PR_LLCORNER=${altchar[m]:--}
36 PR_LRCORNER=${altchar[j]:--}
37 PR_URCORNER=${altchar[k]:--}
38
39 case $TERM in
40 xterm*|rxvt*)
41 PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
42 ;;
43 screen)
44 PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
45 ;;
46 *)
47 PR_TITLEBAR=''
48 ;;
49 esac
50
51 ###
52 # Decide the color of the hostname
53 if [[ "$HOSTNAME" = 'gkar' || "$HOSTNAME" = 'delenn' ]]; then
54 PR_HCOLOR="${PR_GREEN}"
55 else
56 case $DOMAIN in
57 "debconf.org")
58 PR_HCOLOR="${PR_CYAN}"
59 ;;
60 "debian.org")
61 PR_HCOLOR="${PR_WHITE}"
62 ;;
63 *)
64 PR_HCOLOR="${PR_RED}"
65 ;;
66 esac
67 fi
68
69 ###
70 # Finally, the prompt.
71
72 PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
73 $PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
74 $PR_GREEN%(!.%SROOT%s.%n)$PR_GREEN@$PR_HCOLOR%m$PR_GREEN:%l\
75 $PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_HBAR${(e)PR_APM}\
76 $PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR$PR_HBAR${(e)PR_FILLBAR}$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
77 $PR_MAGENTA%$PR_PWDLEN<...<%~%<<\
78 $PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_URCORNER$PR_SHIFT_OUT\
79
80 $PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
81 %(?..$PR_LIGHT_RED%?$PR_BLUE:)\
82 $PR_YELLOW%D{%H:%M}$PR_BLUE)\
83 $PR_WHITE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT${debian_chroot:+($debian_chroot)}${PR_NO_COLOR}\
84 $PR_SHIFT_IN$PR_HBAR $PR_SHIFT_OUT${vcs_info_msg_0_}\
85 $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
86 $PR_NO_COLOUR| '
87
88 RPROMPT=' |$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
89 ($PR_YELLOW%D{%a,%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