Fix bug, add support for directory
This commit is contained in:
parent
68ba5323de
commit
b83dde6fcb
16
zsh/bin/swap
16
zsh/bin/swap
|
@ -1,9 +1,21 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
# Swap files
|
# 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`
|
local tmp=`mktemp`
|
||||||
mv "$1" "$tmp"
|
mv "$1" "$tmp"
|
||||||
mv "$2" "$1"
|
mv "$2" "$1"
|
||||||
mv "$tmp" "$2"
|
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
|
||||||
|
|
Loading…
Reference in New Issue