From 2a8c8343d48b30ef0b497b2a13bedbcdd9077529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Mon, 13 Dec 2021 02:10:22 +0300 Subject: frsync Shortcut script to rsync files between two local/remote directories --- dotfiles/.local/bin/frsync | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 dotfiles/.local/bin/frsync 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 -- cgit v1.2.3