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

Reviewed-on: https://codeberg.org/vlw/dotfiles/pulls/103
This commit is contained in:
Victor Westerlund 2026-01-15 15:45:45 +01:00
parent 0655fbf942
commit 746497fcf0

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 |
# +-----+ # +-----+