From: Alexander Barton Date: Wed, 17 Jan 2024 09:48:52 +0000 (+0100) Subject: std_functions: Enhance take(), introduce untake() X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b61fb4a146c3049ef362511886e19f1f78545472;p=ax-zsh.git std_functions: Enhance take(), introduce untake() 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(). --- diff --git a/default_plugins/std_functions/std_functions.zshrc b/default_plugins/std_functions/std_functions.zshrc index 373ac11..69d6511 100644 --- a/default_plugins/std_functions/std_functions.zshrc +++ b/default_plugins/std_functions/std_functions.zshrc @@ -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() {