From b61fb4a146c3049ef362511886e19f1f78545472 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Wed, 17 Jan 2024 10:48:52 +0100 Subject: [PATCH] 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(). --- .../std_functions/std_functions.zshrc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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() { -- 2.39.2