From 746497fcf0dcb108e92c8b395041f8251ad82f17 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Thu, 15 Jan 2026 15:45:45 +0100 Subject: [PATCH] feat(bash): add function for swapping two file or folder locations (#103) Reviewed-on: https://codeberg.org/vlw/dotfiles/pulls/103 --- .bash_aliases | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.bash_aliases b/.bash_aliases index 870b977..834a76d 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -149,6 +149,25 @@ mkd () { 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 \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 | # +-----+