Add zsh to ignored commands for the prompt bell
[zsh.git] / .zsh / 05_Functions.zsh
1 # -*- mode: sh;-*-
2
3 ## User-defined functions
4 #
5 preprint()
6 {
7 local my_color start stop pipe1 pipe2 hbar out
8
9 if [[ "$COLORS" == "true" ]]; then
10 my_color=${2:-${BOLD_RED}}
11 else
12 my_color=${2:-""}
13 fi
14 if [[ $LINEDRAW == "true" ]]; then
15 # Some stuff to help us draw nice lines
16 if isutf8 || isconsole; then
17 start=""
18 stop=""
19 hbar="─"
20 PR_ULCORNER="┌"
21 PR_LLCORNER="└"
22 PR_LRCORNER="┘"
23 PR_URCORNER="┐"
24 else
25 start="$terminfo[smacs]"
26 stop="$terminfo[rmacs]"
27 hbar="q"
28 pipe1="u"
29 pipe2="t"
30 draw="q"
31 fi
32 else
33 start=""
34 stop=""
35 hbar="-"
36 pipe1="|"
37 pipe2="|"
38 draw="-"
39 fi
40 hbar="${start}${${(l:$(( 74 - ${#1} - 5 ))::X:)}//X/$hbar}${stop}"
41 out="${my_color}${hbar}${start}"
42
43 if [[ "${1}" != "" ]]; then
44 out+="${pipe1}${stop}${my_color} $1 ${my_color}${start}${pipe2}"
45 else
46 out+="${draw}${draw}${draw}${draw}"
47 fi
48 out+="${draw}${stop}${NO_COLOR}\r"
49
50 print -Pn -- $out
51 }
52
53 _jj_chpwd()
54 {
55 if ( is-callable git && test -d .git ); then
56 # Shows tracked branches and modified files
57 git checkout HEAD 2>&1 | sed 's/^/ /'
58 fi
59 }
60
61 if is434 ; then
62 add-zsh-hook chpwd _jj_chpwd
63 else
64 function chpwd() {
65 _jj_chpwd
66 }
67 fi
68
69 # Idea taken from oh-my-zsh, but code is different
70 function dirpersistrestore () {
71 if [ -f ${DIRSTACKFILE} ]; then
72 dirstack=( ${(f)"$(< ${DIRSTACKFILE} )"} )
73 if zstyle -t ':ganneff:config' dirstackhandling dirpersist; then
74 cd -q ${dirstack[-1]}
75 fi
76 fi
77 }
78
79 function dirpersiststore () {
80 print -l ${(Oau)dirstack} ${PWD} >| ${DIRSTACKFILE}
81 }
82
83 if is434; then
84 add-zsh-hook zshexit dirpersiststore
85 else
86 echo "Sorry, zsh version too old"
87 fi