From 34cd8add4ac49585ca3b068d4e63bd2a485c466e Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Wed, 16 Oct 2024 02:01:24 -0400 Subject: [PATCH] shells/zsh: add mktmpunzip and mktmpclone --- users/modules/global/shells/zsh.nix | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/users/modules/global/shells/zsh.nix b/users/modules/global/shells/zsh.nix index 5b49cd2..f533de3 100644 --- a/users/modules/global/shells/zsh.nix +++ b/users/modules/global/shells/zsh.nix @@ -48,6 +48,36 @@ alias "jh"="cd ~ && j" alias "gj"="gcd && j" + + mktmpunzip() { + dir=$(mktemp -t -d unzip.XXX) + if ! file=$(realpath -e "$1"); then + echo "error: file does not exist" + return 1 + fi + shift 1 + unzip "$file" "$@" -d "$dir" + \builtin cd $dir + mv $file . + } + + mktmpclone() { + location="$1" + if [ "$2" != "" ]; then + dirspec="$2.XXX" + shift 2 + else + dirspec="clone.XXX" + shift 1 + fi + if ! dir=$(mktemp -t -d "$dirspec"); then + echo "error: couldn't create temp directory" + return 1 + fi + + git clone "$location" "$dir" "$@" + \builtin cd "$dir" + } ''; dotDir = ".config/zsh";