aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-12-13 02:10:22 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-12-13 02:10:22 +0300
commit2a8c8343d48b30ef0b497b2a13bedbcdd9077529 (patch)
tree97d6052b163287e690aac94720b9154013e47eb0
parent9c45f84e3cf5db8349a487f5ef3ca0c5277dc7aa (diff)
downloadswayrice-2a8c8343d48b30ef0b497b2a13bedbcdd9077529.tar.gz
swayrice-2a8c8343d48b30ef0b497b2a13bedbcdd9077529.zip
frsync
Shortcut script to rsync files between two local/remote directories
-rwxr-xr-xdotfiles/.local/bin/frsync35
1 files changed, 35 insertions, 0 deletions
diff --git a/dotfiles/.local/bin/frsync b/dotfiles/.local/bin/frsync
new file mode 100755
index 0000000..f61defc
--- /dev/null
+++ b/dotfiles/.local/bin/frsync
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# Shortcut script to rsync files between two local/remote directories
+# Looks for a matching line in ~/.config/frsync.conf
+# Lines in said config look like this:
+# remote-docs ~/docs/ remote:docs/
+
+opts="-avh --delete"
+
+if [ "$1" = "-n" ]; then
+ opts="-avhn --delete"
+ direction="$2"
+ target="$3"
+else
+ direction="$1"
+ target="$2"
+fi
+
+l=$(grep "$target" $HOME/.config/frsync.conf)
+
+[ -z "$l" ] && echo "No such target $target" && exit 1
+
+if [ "$direction" = "up" ]; then
+ src=$(echo "$l" | cut -f2)
+ dst=$(echo "$l" | cut -f3)
+else
+ src=$(echo "$l" | cut -f3)
+ dst=$(echo "$l" | cut -f2)
+fi
+
+src=${src/#\~/$HOME}
+dst=${dst/#\~/$HOME}
+
+echo "rsync $opts $src $dst"
+rsync $opts $src $dst