Fixup drawing in preprint
[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 PR_ULCORNER="┌"
20 PR_LLCORNER="└"
21 PR_LRCORNER="┘"
22 PR_URCORNER="┐"
23 draw="─"
24 else
25 start="$terminfo[smacs]"
26 stop="$terminfo[rmacs]"
27 pipe1="u"
28 pipe2="t"
29 draw="q"
30 fi
31 else
32 start=""
33 stop=""
34 pipe1="|"
35 pipe2="|"
36 draw="-"
37 fi
38 hbar="${start}${${(l:$(( 74 - ${#1} - 5 ))::X:)}//X/$draw}${stop}"
39 out="${my_color}${hbar}${start}"
40
41 if [[ "${1}" != "" ]]; then
42 out+="${pipe1}${stop}${my_color} $1 ${my_color}${start}${pipe2}"
43 else
44 out+="${draw}${draw}"
45 fi
46 out+="${draw}${stop}${NO_COLOR}\r"
47
48 print -Pn -- $out
49 }
50
51 _jj_chpwd()
52 {
53 if ( is-callable git && test -d .git ); then
54 # Shows tracked branches and modified files
55 git checkout HEAD 2>&1 | sed 's/^/ /'
56 fi
57 }
58
59 if is434 ; then
60 add-zsh-hook chpwd _jj_chpwd
61 else
62 function chpwd() {
63 _jj_chpwd
64 }
65 fi
66
67 # Idea taken from oh-my-zsh, but code is different
68 function dirpersistrestore () {
69 if [ -f ${DIRSTACKFILE} ]; then
70 dirstack=( ${(f)"$(< ${DIRSTACKFILE} )"} )
71 if zstyle -t ':ganneff:config' dirstackhandling dirpersist; then
72 cd -q ${dirstack[-1]}
73 fi
74 fi
75 }
76
77 function dirpersiststore () {
78 print -l ${(Oau)dirstack} ${PWD} >| ${DIRSTACKFILE}
79 }
80
81 if is434; then
82 add-zsh-hook zshexit dirpersiststore
83 else
84 echo "Sorry, zsh version too old"
85 fi