From b33680e04a20f21bbaecf496945cadd7ef2b25b7 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sun, 26 Jun 2016 21:16:19 -0400 Subject: [PATCH] Great changes in dedir --- shells/zshrc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/shells/zshrc b/shells/zshrc index d5763b7..54643fd 100644 --- a/shells/zshrc +++ b/shells/zshrc @@ -56,14 +56,17 @@ dsl() { } # Remove directory by removing subdirectories up a level dedir(){ - chronic rmdir "$1" -v && return + # Try removing the directory if it's empty, fail silently if you can't + =rmdir "$1" 2>/dev/null && return + # Make a uuid to avoid name conflicts + # Ex: dediring sage when sage/sage fails because sage/sage is moved to . + # but since sage/ exists, it can't be moved name=$(uuidgen) - # Move it to a random name without clobbering, this prevents things like - # files/files - # From erroring because you can't move files/files to . - chronic mv -n "$1" "$name" || return 5 - chronic mv "$name"/*(D) . - chronic rmdir -v "$name" + # Move the directory to the uuid + =mv -n "$1" "$name" || return 1 + # Move all files, use (N) in case there is no * or .* matches + =mv -n "$name"/{.,}*(N) . || return 2 + =rmdir "$name" || return 3 } alias afci='git x ./autoformat.sh;git add --all;git commit -m "Autoformatted"' alias eix="eix -F"