dotfiles/bin/swap

23 lines
443 B
Plaintext
Raw Normal View History

2019-05-03 09:45:06 +02:00
#!/usr/bin/env bash
2019-02-11 17:40:33 +01:00
# Swap files
2019-04-24 16:03:43 +02:00
if [ $# -ne 2 ]; then
echo -e "\033[1;31merror:\033[0m expected two arguments"
exit 1
fi
if [ -f $1 ] && [ -f $2 ]; then
2019-05-03 09:45:06 +02:00
tmp=`mktemp`
2019-02-11 17:40:33 +01:00
mv "$1" "$tmp"
mv "$2" "$1"
mv "$tmp" "$2"
2019-04-24 16:03:43 +02:00
elif [ -d $1 ] && [ -d $2 ]; then
2019-05-03 09:45:06 +02:00
tmp=`mktemp -d`
2019-04-24 16:03:43 +02:00
mv "$1" "$tmp"
mv "$2" "$1"
mv "$tmp/$1" "$2"
else
echo -e "\033[1;31merror:\033[0m expected two files or two directories"
2019-06-07 15:50:48 +02:00
exit 1
2019-04-24 16:03:43 +02:00
fi