From 59e54bd97f70711573d321f2d2aeee5da46bf95d Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 2 Oct 2022 18:46:48 +0200 Subject: ... --- accounts/gkleen@sif/zshrc | 68 ++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 24 deletions(-) (limited to 'accounts') 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() { s() { dir=$(pwd) [[ ${#@} -ge 1 ]] && dir=$1 - + shellFile=$(findNix ${@}) [[ ${#@} -ge 1 ]] && shift @@ -137,7 +137,7 @@ dir() { *) printf "Invalid option: %s\n" $arg >&2; exit 2 ;; esac done - + shift $((OPTIND - 1)) if [[ -z ${dir} && ${#@} -ge 1 ]]; then @@ -145,7 +145,7 @@ dir() { shift fi - [[ -n ${dir} ]] || return 2; + [[ -n ${dir} ]] || return 2; if [[ ! -e ${dir} ]]; then if [[ -z "${gitWorktree}" ]]; then @@ -156,7 +156,7 @@ dir() { else gitWorktree="" fi - + ( cd ${dir} export dir; @@ -164,7 +164,7 @@ dir() { ${findNix} && { nixShell=$(findNix) || return $? } [[ -n ${repoUrl} ]] && git clone -- ${repoUrl} . - + if [[ -n ${templateArchive} ]]; then ( archiveFile="" @@ -181,16 +181,36 @@ dir() { templateArchive=${archiveFile} fi - case $(file --brief --mime-type --dereference ${templateArchive}) in - application/zip) unzip ${templateArchive} ;; - application/vnd.debian.binary-package) - nix shell nixos#binutils --command ar x ${templateArchive} - mkdir control data - tar -C control -xvaf control.* - tar -C data -xvaf data.* - ;; - *) tar -xvaf ${templateArchive} ;; - esac + unpack=true + while ${unpack}; do + case $(file --brief --mime-type --dereference ${templateArchive}) in + application/zip) + unzip ${templateArchive} + unpack=false + ;; + application/vnd.debian.binary-package) + nix shell nixos#binutils --command ar x ${templateArchive} + mkdir control data + tar -C control -xvaf control.* + tar -C data -xvaf data.* + unpack=false + ;; + application/x-rpm) + cpioArchive=$(mktemp -t "archive.XXXXXXXXXX.${templateArchive:t:r}.cpio") + nix shell nixos#busybox --command rpm2cpio ${templateArchive} > ${cpioArchive} + templateArchive=${cpioArchive} + unpack=true + ;; + application/x-cpio) + cpio --extract --make-directories --no-absolute-filenames -F ${templateArchive} + unpack=false + ;; + *) + tar -xvaf ${templateArchive} + unpack=false + ;; + esac + done ) fi @@ -202,7 +222,7 @@ dir() { # typeset -a messages # messages=(${(z)$(notmuch search --output=messages ${notmuchMsg})}) - + # for message (${messages}); do # typeset -A notmuchAtts # notmuchAtts=() @@ -253,7 +273,7 @@ dir() { quickserve --root . --upload . --show-hidden --tar gz fi - + if [[ ${#@} -eq 0 ]] || ${forceShell}; then if [[ ${#@} -gt 0 ]]; then if [[ -z ${nixShell} ]]; then @@ -264,11 +284,11 @@ dir() { fi cd $(pwd) # Needed for mounting to work - + isSingleDir() { typeset -a contents contents=(*(N) .*(N)) - + if [[ ${#contents} -eq 1 && -d ${contents[1]} ]]; then print ${contents[1]} return 0 @@ -278,7 +298,7 @@ dir() { } while d=$(isSingleDir); do cd ${d}; done - + if [[ -z ${nixShell} ]]; then exec -- zsh else @@ -302,7 +322,7 @@ tmpdir() { printf "Unmounting %s\n" ${1} >&2 fusermount -u ${1} || umount ${1} || sudo umount ${1} } - + if mountpoint -q -- ${dir}; then unmount ${dir} || return $? else @@ -311,7 +331,7 @@ tmpdir() { unmount ${subDir} || return $? done <<<$(find ${dir} -xdev -type d -print0 | sort -zr) fi - + rm -rfv --one-file-system -- ${dir} } @@ -323,7 +343,7 @@ tmpdir() { "?"|":") printf "Invalid option: %s\n" $arg >&2; exit 2 ;; esac done - + ( trap cleanup EXIT @@ -362,7 +382,7 @@ nix-ghci() { pkgExpr="${1}" shift fi - + nix-shell -p "with (import {}); pkgs.haskellPackages.ghcWithPackages (p: with p; [${pkgExpr}])" --run "ghci ${@}" } -- cgit v1.2.3