From ff768043d905e60b8448da3810a7cd38f8b47085 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sat, 27 Jan 2007 12:43:53 +0000 Subject: Use shell expansion of remote homedir (~) when host contains user. --- localsyncthis | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'localsyncthis') diff --git a/localsyncthis b/localsyncthis index c1c0346..99b68f3 100755 --- a/localsyncthis +++ b/localsyncthis @@ -79,17 +79,28 @@ fi while [ -n "$workdir" ]; do for host in $hosts; do + thisdir="$localdir$workdir" thatdir="$remotedir$workdir" + shellmagic="" + + if [ -z "$localdir" ] && echo "$host" | grep -q '@'; then + relativeworkdir=$(echo "$workdir" | sed "s|^$HOME/\?||") + if [ "$workdir" != "$relativeworkdir" ]; then + thisdir="$workdir" + thatdir="$relativeworkdir" + shellmagic="~/" + fi + fi case $action in download) - rsync --rsh="ssh $ssh_opts" $rsync_opts "$host:'$thatdir/'" "$thisdir" - [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts "$host:'$thatdir/'" "$thisdir" + [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts "$host:$shellmagic'$thatdir/'" "$thisdir" + rsync --rsh="ssh $ssh_opts" $rsync_opts "$host:$shellmagic'$thatdir/'" "$thisdir" ;; upload) - rsync --rsh="ssh $ssh_opts" $rsync_opts "$thisdir/" "$host:'$thatdir'" - [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts "$thisdir/" "$host:'$thatdir'" + [ $V ] && echo rsync --rsh="ssh $ssh_opts" $rsync_opts "$thisdir/" "$host:$shellmagic'$thatdir'" + rsync --rsh="ssh $ssh_opts" $rsync_opts "$thisdir/" "$host:$shellmagic'$thatdir'" ;; *) echo "$prg error: You need to specify either --upload or --download!" echo -- cgit v1.2.3