]> arthur.barton.de Git - ax-zsh.git/blobdiff - default_plugins/std_functions/std_functions.zshrc
std_functions: Enhance take(), introduce untake()
[ax-zsh.git] / 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() {