feat(bash): add function for swapping two file or folder locations

This commit is contained in:
Victor Westerlund 2026-01-15 15:40:03 +01:00
parent 0655fbf942
commit 2bd4aa4603
Signed by: vlw
GPG key ID: D0AD730E1057DFC6

View file

@ -149,6 +149,25 @@ mkd () {
mkdir -p -- "$1" && cd -P -- "$1" && l mkdir -p -- "$1" && cd -P -- "$1" && l
} }
# Swap the location of a file or folder with another file or folder
swp () {
if [ "$#" -ne 2 ]; then
echo -e "\e[0;91mExpected two arguments: swp <from> <to>\e[0m"
return 1
fi
if [ ! -e $1 ]; then
echo -e "\e[0;91m'$1' is not a file or folder\e[0m"
return 1
fi
tmp_suffix=$RANDOM
mv $1 "$1.$tmp_suffix"
mv $2 $1
mv "$1.$tmp_suffix" $2
}
# +-----+ # +-----+
# | Git | # | Git |
# +-----+ # +-----+