diff options
Diffstat (limited to 'accounts/gkleen@sif/zshrc')
| -rw-r--r-- | accounts/gkleen@sif/zshrc | 62 |
1 files changed, 19 insertions, 43 deletions
diff --git a/accounts/gkleen@sif/zshrc b/accounts/gkleen@sif/zshrc index c628e2e9..06f6f6f2 100644 --- a/accounts/gkleen@sif/zshrc +++ b/accounts/gkleen@sif/zshrc | |||
| @@ -2,8 +2,6 @@ dir() { | |||
| 2 | curlArchive=false | 2 | curlArchive=false |
| 3 | templateArchive="" | 3 | templateArchive="" |
| 4 | repoUrl="" | 4 | repoUrl="" |
| 5 | nixShell="" | ||
| 6 | findNix=false | ||
| 7 | dir="" | 5 | dir="" |
| 8 | forceShell=false | 6 | forceShell=false |
| 9 | wormhole=false | 7 | wormhole=false |
| @@ -12,7 +10,7 @@ dir() { | |||
| 12 | quickserve=false | 10 | quickserve=false |
| 13 | modifyPDF="" | 11 | modifyPDF="" |
| 14 | 12 | ||
| 15 | while getopts ':t:a:s:Sd:ir:wqg:p:' arg; do | 13 | while getopts ':t:a:d:ir:wqg:p:' arg; do |
| 16 | case $arg in | 14 | case $arg in |
| 17 | "t") ;; | 15 | "t") ;; |
| 18 | "a") | 16 | "a") |
| @@ -23,8 +21,6 @@ dir() { | |||
| 23 | templateArchive=${OPTARG:a} | 21 | templateArchive=${OPTARG:a} |
| 24 | fi | 22 | fi |
| 25 | ;; | 23 | ;; |
| 26 | "s") nixShell=${OPTARG:a} ;; | ||
| 27 | "S") findNix=true ;; | ||
| 28 | "d") dir=${OPTARG} ;; | 24 | "d") dir=${OPTARG} ;; |
| 29 | "i") forceShell=true ;; | 25 | "i") forceShell=true ;; |
| 30 | "r") repoUrl=${OPTARG} ;; | 26 | "r") repoUrl=${OPTARG} ;; |
| @@ -59,7 +55,11 @@ dir() { | |||
| 59 | cleanup() | 55 | cleanup() |
| 60 | { | 56 | { |
| 61 | cd ${modifyPDF:h} | 57 | cd ${modifyPDF:h} |
| 62 | [[ -n ${modifyPDF} ]] && nix shell 'nixos#imagemagick' -c convert -verbose ${dir}/${modifyPDF:t:r}_*.png(on) ${modifyPDF} | 58 | if [[ -n ${modifyPDF} ]]; then |
| 59 | typeset -a pages | ||
| 60 | eval 'pages=(${dir}/${modifyPDF:t:r}_*.png(on))' | ||
| 61 | magick -verbose "$pages" ${modifyPDF} | ||
| 62 | fi | ||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | ( | 65 | ( |
| @@ -68,8 +68,6 @@ dir() { | |||
| 68 | cd ${dir} | 68 | cd ${dir} |
| 69 | export dir; | 69 | export dir; |
| 70 | 70 | ||
| 71 | ${findNix} && { nixShell=$(findNix) || return $? } | ||
| 72 | |||
| 73 | [[ -n ${repoUrl} ]] && git clone -- ${repoUrl} . | 71 | [[ -n ${repoUrl} ]] && git clone -- ${repoUrl} . |
| 74 | 72 | ||
| 75 | [[ -n ${modifyPDF} ]] && templateArchive=${modifyPDF} | 73 | [[ -n ${modifyPDF} ]] && templateArchive=${modifyPDF} |
| @@ -82,7 +80,7 @@ dir() { | |||
| 82 | } | 80 | } |
| 83 | trap cleanup EXIT | 81 | trap cleanup EXIT |
| 84 | 82 | ||
| 85 | if ${curlArchive}; then | 83 | if [[ $curlArchive = "true" ]]; then |
| 86 | archiveFile=$(mktemp -t "archive.XXXXXXXXXX.${templateArchive:t}") | 84 | archiveFile=$(mktemp -t "archive.XXXXXXXXXX.${templateArchive:t}") |
| 87 | 85 | ||
| 88 | curl -L -o ${archiveFile} ${templateArchive} | 86 | curl -L -o ${archiveFile} ${templateArchive} |
| @@ -91,14 +89,14 @@ dir() { | |||
| 91 | fi | 89 | fi |
| 92 | 90 | ||
| 93 | unpack=true | 91 | unpack=true |
| 94 | while ${unpack}; do | 92 | while [[ $unpack = "true" ]]; do |
| 95 | case $(file --brief --mime-type --dereference ${templateArchive}) in | 93 | case $(file --brief --mime-type --dereference ${templateArchive}) in |
| 96 | application/zip) | 94 | application/zip) |
| 97 | unzip ${templateArchive} | 95 | unzip ${templateArchive} |
| 98 | unpack=false | 96 | unpack=false |
| 99 | ;; | 97 | ;; |
| 100 | application/vnd.debian.binary-package) | 98 | application/vnd.debian.binary-package) |
| 101 | nix shell 'nixos#binutils' --command ar x ${templateArchive} | 99 | ar x ${templateArchive} |
| 102 | mkdir control data | 100 | mkdir control data |
| 103 | tar -C control -xvaf control.* | 101 | tar -C control -xvaf control.* |
| 104 | tar -C data -xvaf data.* | 102 | tar -C data -xvaf data.* |
| @@ -106,7 +104,7 @@ dir() { | |||
| 106 | ;; | 104 | ;; |
| 107 | application/x-rpm) | 105 | application/x-rpm) |
| 108 | cpioArchive=$(mktemp -t "archive.XXXXXXXXXX.${templateArchive:t:r}.cpio") | 106 | cpioArchive=$(mktemp -t "archive.XXXXXXXXXX.${templateArchive:t:r}.cpio") |
| 109 | nix shell 'nixos#busybox' --command rpm2cpio ${templateArchive} > ${cpioArchive} | 107 | rpm2cpio ${templateArchive} > ${cpioArchive} |
| 110 | templateArchive=${cpioArchive} | 108 | templateArchive=${cpioArchive} |
| 111 | unpack=true | 109 | unpack=true |
| 112 | ;; | 110 | ;; |
| @@ -115,12 +113,12 @@ dir() { | |||
| 115 | unpack=false | 113 | unpack=false |
| 116 | ;; | 114 | ;; |
| 117 | application/pdf) | 115 | application/pdf) |
| 118 | nix shell 'nixos#ghostscript' 'nixos#imagemagick' -c convert -verbose -density 400 ${templateArchive} ${modifyPDF:t:r}_%0d.png | 116 | magick -verbose -density 400 ${templateArchive} ${modifyPDF:t:r}_%0d.png |
| 119 | unpack=false | 117 | unpack=false |
| 120 | ;; | 118 | ;; |
| 121 | application/octet-stream) | 119 | application/octet-stream) |
| 122 | if [[ $(file --brief --dereferenc ${templateArchive}) =~ Squashfs ]]; then | 120 | if [[ $(file --brief --dereference ${templateArchive}) =~ Squashfs ]]; then |
| 123 | nix shell 'nixos#squashfsTools' -c unsquashfs -d . ${templateArchive} | 121 | unsquashfs -d . ${templateArchive} |
| 124 | unpack=false | 122 | unpack=false |
| 125 | fi | 123 | fi |
| 126 | ;; | 124 | ;; |
| @@ -134,21 +132,17 @@ dir() { | |||
| 134 | fi | 132 | fi |
| 135 | 133 | ||
| 136 | 134 | ||
| 137 | ${wormhole} && wormhole receive --accept-file | 135 | [[ $wormhole = "true" ]] && wormhole receive --accept-file |
| 138 | 136 | ||
| 139 | 137 | ||
| 140 | if ${quickserve}; then | 138 | if [[ $quickserve = "true" ]]; then |
| 141 | quickserve --root . --upload . --show-hidden --tar gz | 139 | quickserve --root . --upload . --show-hidden --tar gz |
| 142 | fi | 140 | fi |
| 143 | 141 | ||
| 144 | 142 | ||
| 145 | if [[ ${#@} -eq 0 ]] || ${forceShell}; then | 143 | if [[ ${#@} -eq 0 ]] || [[ $forceShell = "true" ]]; then |
| 146 | if [[ ${#@} -gt 0 ]]; then | 144 | if [[ ${#@} -gt 0 ]]; then |
| 147 | if [[ -z ${nixShell} ]]; then | 145 | ${@} |
| 148 | ${@} | ||
| 149 | else | ||
| 150 | nix-shell ${nixShell} --run "${@}" | ||
| 151 | fi | ||
| 152 | fi | 146 | fi |
| 153 | 147 | ||
| 154 | cd $(pwd) # Needed for mounting to work | 148 | cd $(pwd) # Needed for mounting to work |
| @@ -167,17 +161,9 @@ dir() { | |||
| 167 | while d=$(isSingleDir); do cd ${d}; done | 161 | while d=$(isSingleDir); do cd ${d}; done |
| 168 | 162 | ||
| 169 | 163 | ||
| 170 | if [[ -z ${nixShell} ]]; then | 164 | zsh |
| 171 | zsh | ||
| 172 | else | ||
| 173 | nix-shell ${nixShell} --run zsh | ||
| 174 | fi | ||
| 175 | else | 165 | else |
| 176 | if [[ -z ${nixShell} ]]; then | 166 | ${@} |
| 177 | ${@} | ||
| 178 | else | ||
| 179 | nix-shell ${nixShell} --run "${@}" | ||
| 180 | fi | ||
| 181 | fi | 167 | fi |
| 182 | ) | 168 | ) |
| 183 | } | 169 | } |
| @@ -234,16 +220,6 @@ public-ip() { | |||
| 234 | curl -s -H 'Accept: application/json' $@ ifconfig.co | jq -r '.ip' | 220 | curl -s -H 'Accept: application/json' $@ ifconfig.co | jq -r '.ip' |
| 235 | } | 221 | } |
| 236 | 222 | ||
| 237 | nix-ghci() { | ||
| 238 | pkgExpr="" | ||
| 239 | if [[ ${#@} -gt 0 ]]; then | ||
| 240 | pkgExpr="${1}" | ||
| 241 | shift | ||
| 242 | fi | ||
| 243 | |||
| 244 | nix-shell -p "with (import <nixpkgs> {}); pkgs.haskellPackages.ghcWithPackages (p: with p; [${pkgExpr}])" --run "ghci ${@}" | ||
| 245 | } | ||
| 246 | |||
| 247 | swap() { | 223 | swap() { |
| 248 | f1=${1} | 224 | f1=${1} |
| 249 | f2=${2} | 225 | f2=${2} |
