summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/zshrc
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@sif/zshrc')
-rw-r--r--accounts/gkleen@sif/zshrc80
1 files changed, 43 insertions, 37 deletions
diff --git a/accounts/gkleen@sif/zshrc b/accounts/gkleen@sif/zshrc
index 06f6f6f2..7645e0fc 100644
--- a/accounts/gkleen@sif/zshrc
+++ b/accounts/gkleen@sif/zshrc
@@ -6,11 +6,10 @@ dir() {
6 forceShell=false 6 forceShell=false
7 wormhole=false 7 wormhole=false
8 gitWorktree="" 8 gitWorktree=""
9 # notmuchMsg=""
10 quickserve=false
11 modifyPDF="" 9 modifyPDF=""
10 miniserve=false
12 11
13 while getopts ':t:a:d:ir:wqg:p:' arg; do 12 while getopts ':t:a:d:ir:wg:p:m' arg; do
14 case $arg in 13 case $arg in
15 "t") ;; 14 "t") ;;
16 "a") 15 "a")
@@ -26,9 +25,8 @@ dir() {
26 "r") repoUrl=${OPTARG} ;; 25 "r") repoUrl=${OPTARG} ;;
27 "w") wormhole=true ;; 26 "w") wormhole=true ;;
28 "g") gitWorktree=${OPTARG} ;; 27 "g") gitWorktree=${OPTARG} ;;
29 # "n") notmuchMsg=${OPTARG} ;;
30 "q") quickserve=true ;;
31 "p") modifyPDF=${OPTARG:a} ;; 28 "p") modifyPDF=${OPTARG:a} ;;
29 "m") miniserve=true ;;
32 *) printf "Invalid option: %s\n" $arg >&2; exit 2 ;; 30 *) printf "Invalid option: %s\n" $arg >&2; exit 2 ;;
33 esac 31 esac
34 done 32 done
@@ -52,17 +50,29 @@ dir() {
52 gitWorktree="" 50 gitWorktree=""
53 fi 51 fi
54 52
53 miniservePIDFile=""
54 if [[ ${miniserve} = "true" ]]; then
55 miniservePIDFile=$(mktemp --tmpdir --suffix=.pid)
56 fi
57
55 cleanup() 58 cleanup()
56 { 59 {
57 cd ${modifyPDF:h}
58 if [[ -n ${modifyPDF} ]]; then 60 if [[ -n ${modifyPDF} ]]; then
61 cd ${modifyPDF:h}
59 typeset -a pages 62 typeset -a pages
60 eval 'pages=(${dir}/${modifyPDF:t:r}_*.png(on))' 63 eval 'pages=(${dir}/${modifyPDF:t:r}_*.png(on))'
61 magick -verbose "$pages" ${modifyPDF} 64 magick -verbose "$pages" ${modifyPDF}
65 modifyPDF=""
66 fi
67 if [[ -n ${miniservePIDFile} ]]; then
68 kill --verbose $(cat ${miniservePIDFile}) && wait $(cat ${miniservePIDFile})
69 miniservePIDFile=""
62 fi 70 fi
63 } 71 }
64 72
65 ( 73 (
74 set -o localtraps
75 trap 'return 1' INT TERM
66 trap cleanup EXIT 76 trap cleanup EXIT
67 77
68 cd ${dir} 78 cd ${dir}
@@ -135,18 +145,18 @@ dir() {
135 [[ $wormhole = "true" ]] && wormhole receive --accept-file 145 [[ $wormhole = "true" ]] && wormhole receive --accept-file
136 146
137 147
138 if [[ $quickserve = "true" ]]; then 148 if [[ ${#@} -gt 0 ]]; then
139 quickserve --root . --upload . --show-hidden --tar gz 149 ${@}
140 fi 150 fi
141 151
152 cd $(pwd) # Needed for mounting to work
142 153
143 if [[ ${#@} -eq 0 ]] || [[ $forceShell = "true" ]]; then 154 if [[ ${miniserve} = "true" ]]; then
144 if [[ ${#@} -gt 0 ]]; then 155 miniserve --random-route --hidden --enable-tar-gz --enable-zip . &
145 ${@} 156 echo $! > "${miniservePIDFile}"
146 fi 157 fi
147
148 cd $(pwd) # Needed for mounting to work
149 158
159 if [[ ${#@} -eq 0 ]] && [[ ${miniserve} != "true" ]] || [[ $forceShell = "true" ]]; then
150 isSingleDir() { 160 isSingleDir() {
151 typeset -a contents 161 typeset -a contents
152 contents=(*(N) .*(N)) 162 contents=(*(N) .*(N))
@@ -160,10 +170,9 @@ dir() {
160 } 170 }
161 while d=$(isSingleDir); do cd ${d}; done 171 while d=$(isSingleDir); do cd ${d}; done
162 172
163
164 zsh 173 zsh
165 else 174 elif [[ ${miniserve} == "true" ]]; then
166 ${@} 175 wait $(cat "${miniservePIDFile}")
167 fi 176 fi
168 ) 177 )
169} 178}
@@ -171,27 +180,30 @@ dir() {
171tmpdir() { 180tmpdir() {
172 cleanup() 181 cleanup()
173 { 182 {
174 cd / 183 cd /
175 unmount() { 184 unmount() {
176 printf "Unmounting %s\n" ${1} >&2 185 printf "Unmounting %s\n" ${1} >&2
177 fusermount -u ${1} || umount ${1} || sudo umount ${1} 186 fusermount -u ${1} || umount ${1} || sudo umount ${1}
178 } 187 }
179 188
180 if mountpoint -q -- ${dir}; then 189 if [[ -n ${dir} ]]; then
181 unmount ${dir} || return $? 190 if mountpoint -q -- ${dir}; then
182 else 191 unmount ${dir} || return $?
183 while read -d $'\0' subDir; do 192 else
184 mountpoint -q -- ${subDir} || continue 193 while read -d $'\0' subDir; do
185 unmount ${subDir} || return $? 194 mountpoint -q -- ${subDir} || continue
186 done <<<$(find ${dir} -xdev -type d -print0 | sort -zr) 195 unmount ${subDir} || return $?
187 fi 196 done <<<$(find ${dir} -xdev -type d -print0 | sort -zr)
188 197 fi
189 rm -rfv --one-file-system -- ${dir} 198
199 rm -rfv --one-file-system -- ${dir}
200 dir=""
201 fi
190 } 202 }
191 203
192 local tmpdir="" 204 local tmpdir=""
193 205
194 while getopts ':t:a:s:Sd:ir:wqg:p:' arg; do 206 while getopts ':t:a:d:ir:wg:p:m' arg; do
195 case $arg in 207 case $arg in
196 "t") tmpdir="=${OPTARG}" ;; 208 "t") tmpdir="=${OPTARG}" ;;
197 "?"|":") printf "Invalid option: %s\n" $arg >&2; exit 2 ;; 209 "?"|":") printf "Invalid option: %s\n" $arg >&2; exit 2 ;;
@@ -199,6 +211,8 @@ tmpdir() {
199 done 211 done
200 212
201 ( 213 (
214 set -o localtraps
215 trap 'return 1' INT TERM
202 trap cleanup EXIT 216 trap cleanup EXIT
203 217
204 218
@@ -247,14 +261,6 @@ l() {
247 ls --long --binary --git --time-style=iso --header $@ 261 ls --long --binary --git --time-style=iso --header $@
248} 262}
249 263
250re() {
251 systemctl restart $@
252}
253
254ure() {
255 systemctl --user restart $@
256}
257
258ssh-installer() { 264ssh-installer() {
259 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/gkleen@sif.midgard.yggdrasil $@ 265 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentityFile=~/.ssh/gkleen@sif.midgard.yggdrasil $@
260} 266}