summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2022-10-02 18:46:48 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2022-10-02 18:46:48 +0200
commit59e54bd97f70711573d321f2d2aeee5da46bf95d (patch)
tree57ad9c1e82af6247afde473cb2f1f3a219599059 /accounts/gkleen@sif
parent410a63cf1baf627a0b99c34a955b3d02efabb48f (diff)
downloadnixos-59e54bd97f70711573d321f2d2aeee5da46bf95d.tar
nixos-59e54bd97f70711573d321f2d2aeee5da46bf95d.tar.gz
nixos-59e54bd97f70711573d321f2d2aeee5da46bf95d.tar.bz2
nixos-59e54bd97f70711573d321f2d2aeee5da46bf95d.tar.xz
nixos-59e54bd97f70711573d321f2d2aeee5da46bf95d.zip
...
Diffstat (limited to 'accounts/gkleen@sif')
-rw-r--r--accounts/gkleen@sif/zshrc68
1 files changed, 44 insertions, 24 deletions
diff --git a/accounts/gkleen@sif/zshrc b/accounts/gkleen@sif/zshrc
index 1b7cc06c..bda73d76 100644
--- a/accounts/gkleen@sif/zshrc
+++ b/accounts/gkleen@sif/zshrc
@@ -45,7 +45,7 @@ genmail() {
45s() { 45s() {
46 dir=$(pwd) 46 dir=$(pwd)
47 [[ ${#@} -ge 1 ]] && dir=$1 47 [[ ${#@} -ge 1 ]] && dir=$1
48 48
49 shellFile=$(findNix ${@}) 49 shellFile=$(findNix ${@})
50 [[ ${#@} -ge 1 ]] && shift 50 [[ ${#@} -ge 1 ]] && shift
51 51
@@ -137,7 +137,7 @@ dir() {
137 *) printf "Invalid option: %s\n" $arg >&2; exit 2 ;; 137 *) printf "Invalid option: %s\n" $arg >&2; exit 2 ;;
138 esac 138 esac
139 done 139 done
140 140
141 shift $((OPTIND - 1)) 141 shift $((OPTIND - 1))
142 142
143 if [[ -z ${dir} && ${#@} -ge 1 ]]; then 143 if [[ -z ${dir} && ${#@} -ge 1 ]]; then
@@ -145,7 +145,7 @@ dir() {
145 shift 145 shift
146 fi 146 fi
147 147
148 [[ -n ${dir} ]] || return 2; 148 [[ -n ${dir} ]] || return 2;
149 149
150 if [[ ! -e ${dir} ]]; then 150 if [[ ! -e ${dir} ]]; then
151 if [[ -z "${gitWorktree}" ]]; then 151 if [[ -z "${gitWorktree}" ]]; then
@@ -156,7 +156,7 @@ dir() {
156 else 156 else
157 gitWorktree="" 157 gitWorktree=""
158 fi 158 fi
159 159
160 ( 160 (
161 cd ${dir} 161 cd ${dir}
162 export dir; 162 export dir;
@@ -164,7 +164,7 @@ dir() {
164 ${findNix} && { nixShell=$(findNix) || return $? } 164 ${findNix} && { nixShell=$(findNix) || return $? }
165 165
166 [[ -n ${repoUrl} ]] && git clone -- ${repoUrl} . 166 [[ -n ${repoUrl} ]] && git clone -- ${repoUrl} .
167 167
168 if [[ -n ${templateArchive} ]]; then 168 if [[ -n ${templateArchive} ]]; then
169 ( 169 (
170 archiveFile="" 170 archiveFile=""
@@ -181,16 +181,36 @@ dir() {
181 templateArchive=${archiveFile} 181 templateArchive=${archiveFile}
182 fi 182 fi
183 183
184 case $(file --brief --mime-type --dereference ${templateArchive}) in 184 unpack=true
185 application/zip) unzip ${templateArchive} ;; 185 while ${unpack}; do
186 application/vnd.debian.binary-package) 186 case $(file --brief --mime-type --dereference ${templateArchive}) in
187 nix shell nixos#binutils --command ar x ${templateArchive} 187 application/zip)
188 mkdir control data 188 unzip ${templateArchive}
189 tar -C control -xvaf control.* 189 unpack=false
190 tar -C data -xvaf data.* 190 ;;
191 ;; 191 application/vnd.debian.binary-package)
192 *) tar -xvaf ${templateArchive} ;; 192 nix shell nixos#binutils --command ar x ${templateArchive}
193 esac 193 mkdir control data
194 tar -C control -xvaf control.*
195 tar -C data -xvaf data.*
196 unpack=false
197 ;;
198 application/x-rpm)
199 cpioArchive=$(mktemp -t "archive.XXXXXXXXXX.${templateArchive:t:r}.cpio")
200 nix shell nixos#busybox --command rpm2cpio ${templateArchive} > ${cpioArchive}
201 templateArchive=${cpioArchive}
202 unpack=true
203 ;;
204 application/x-cpio)
205 cpio --extract --make-directories --no-absolute-filenames -F ${templateArchive}
206 unpack=false
207 ;;
208 *)
209 tar -xvaf ${templateArchive}
210 unpack=false
211 ;;
212 esac
213 done
194 ) 214 )
195 fi 215 fi
196 216
@@ -202,7 +222,7 @@ dir() {
202 222
203 # typeset -a messages 223 # typeset -a messages
204 # messages=(${(z)$(notmuch search --output=messages ${notmuchMsg})}) 224 # messages=(${(z)$(notmuch search --output=messages ${notmuchMsg})})
205 225
206 # for message (${messages}); do 226 # for message (${messages}); do
207 # typeset -A notmuchAtts 227 # typeset -A notmuchAtts
208 # notmuchAtts=() 228 # notmuchAtts=()
@@ -253,7 +273,7 @@ dir() {
253 quickserve --root . --upload . --show-hidden --tar gz 273 quickserve --root . --upload . --show-hidden --tar gz
254 fi 274 fi
255 275
256 276
257 if [[ ${#@} -eq 0 ]] || ${forceShell}; then 277 if [[ ${#@} -eq 0 ]] || ${forceShell}; then
258 if [[ ${#@} -gt 0 ]]; then 278 if [[ ${#@} -gt 0 ]]; then
259 if [[ -z ${nixShell} ]]; then 279 if [[ -z ${nixShell} ]]; then
@@ -264,11 +284,11 @@ dir() {
264 fi 284 fi
265 285
266 cd $(pwd) # Needed for mounting to work 286 cd $(pwd) # Needed for mounting to work
267 287
268 isSingleDir() { 288 isSingleDir() {
269 typeset -a contents 289 typeset -a contents
270 contents=(*(N) .*(N)) 290 contents=(*(N) .*(N))
271 291
272 if [[ ${#contents} -eq 1 && -d ${contents[1]} ]]; then 292 if [[ ${#contents} -eq 1 && -d ${contents[1]} ]]; then
273 print ${contents[1]} 293 print ${contents[1]}
274 return 0 294 return 0
@@ -278,7 +298,7 @@ dir() {
278 } 298 }
279 while d=$(isSingleDir); do cd ${d}; done 299 while d=$(isSingleDir); do cd ${d}; done
280 300
281 301
282 if [[ -z ${nixShell} ]]; then 302 if [[ -z ${nixShell} ]]; then
283 exec -- zsh 303 exec -- zsh
284 else 304 else
@@ -302,7 +322,7 @@ tmpdir() {
302 printf "Unmounting %s\n" ${1} >&2 322 printf "Unmounting %s\n" ${1} >&2
303 fusermount -u ${1} || umount ${1} || sudo umount ${1} 323 fusermount -u ${1} || umount ${1} || sudo umount ${1}
304 } 324 }
305 325
306 if mountpoint -q -- ${dir}; then 326 if mountpoint -q -- ${dir}; then
307 unmount ${dir} || return $? 327 unmount ${dir} || return $?
308 else 328 else
@@ -311,7 +331,7 @@ tmpdir() {
311 unmount ${subDir} || return $? 331 unmount ${subDir} || return $?
312 done <<<$(find ${dir} -xdev -type d -print0 | sort -zr) 332 done <<<$(find ${dir} -xdev -type d -print0 | sort -zr)
313 fi 333 fi
314 334
315 rm -rfv --one-file-system -- ${dir} 335 rm -rfv --one-file-system -- ${dir}
316 } 336 }
317 337
@@ -323,7 +343,7 @@ tmpdir() {
323 "?"|":") printf "Invalid option: %s\n" $arg >&2; exit 2 ;; 343 "?"|":") printf "Invalid option: %s\n" $arg >&2; exit 2 ;;
324 esac 344 esac
325 done 345 done
326 346
327 ( 347 (
328 trap cleanup EXIT 348 trap cleanup EXIT
329 349
@@ -362,7 +382,7 @@ nix-ghci() {
362 pkgExpr="${1}" 382 pkgExpr="${1}"
363 shift 383 shift
364 fi 384 fi
365 385
366 nix-shell -p "with (import <nixpkgs> {}); pkgs.haskellPackages.ghcWithPackages (p: with p; [${pkgExpr}])" --run "ghci ${@}" 386 nix-shell -p "with (import <nixpkgs> {}); pkgs.haskellPackages.ghcWithPackages (p: with p; [${pkgExpr}])" --run "ghci ${@}"
367} 387}
368 388