]> arthur.barton.de Git - ax-zsh.git/commitdiff
std_functions: Enhance take(), introduce untake()
authorAlexander Barton <alex@barton.de>
Wed, 17 Jan 2024 09:48:52 +0000 (10:48 +0100)
committerAlexander Barton <alex@barton.de>
Wed, 17 Jan 2024 09:48:54 +0000 (10:48 +0100)
take() now creates an new temporary directory when called without
parameters (and changes the working directory into it).

The new untake() functions changes the current working directory to the
home directory and recursively deletes the old working directory when
the path matches a pattern which is used for temporary directorues
created by take().

default_plugins/std_functions/std_functions.zshrc

index 373ac11b30b278ab2aa553b629f315471279bac8..69d65113ffa2baff69339ebb65560cd75c86ffe5 100644 (file)
@@ -24,7 +24,22 @@ function open_command() {
 }
 
 function take() {
-       mkdir -p "$@" && cd "${@:$#}"
+       if [[ $# -eq 0 ]]; then
+               cd "$(mktemp -d)"
+               pwd
+       else
+               mkdir -p "$@" && cd "${@:$#}"
+       fi
+}
+
+function untake() {
+       if [[ "${PWD%tmp.*}" = "${TMPDIR}" ]]; then
+               pwd
+               cd
+               rm -fri "$@" "${OLDPWD}"
+       else
+               echo 'Sorry, not a temporarily taken directory!' >&2
+       fi
 }
 
 function zsh_stats() {