From b83dde6fcb997ee4bc7d1e4c538ea6349e2830de Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 24 Apr 2019 16:03:43 +0200 Subject: [PATCH] Fix bug, add support for directory --- zsh/bin/swap | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/zsh/bin/swap b/zsh/bin/swap index f595788..bb1e94f 100755 --- a/zsh/bin/swap +++ b/zsh/bin/swap @@ -1,9 +1,21 @@ #!/usr/bin/env zsh # Swap files -swap() { +if [ $# -ne 2 ]; then + echo -e "\033[1;31merror:\033[0m expected two arguments" + exit 1 +fi + +if [ -f $1 ] && [ -f $2 ]; then local tmp=`mktemp` mv "$1" "$tmp" mv "$2" "$1" mv "$tmp" "$2" -} +elif [ -d $1 ] && [ -d $2 ]; then + local tmp=`mktemp -d` + mv "$1" "$tmp" + mv "$2" "$1" + mv "$tmp/$1" "$2" +else + echo -e "\033[1;31merror:\033[0m expected two files or two directories" +fi