diff options
author | Jonas Smedegaard <dr@jones.dk> | 2007-01-27 12:43:53 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2007-01-27 12:43:53 +0000 |
commit | ff768043d905e60b8448da3810a7cd38f8b47085 (patch) | |
tree | 8791dac62017f9b24d9f1bd2010052160b826858 | |
parent | 25297bdacebe733652c821af7fc50042b5f6c785 (diff) |
Use shell expansion of remote homedir (~) when host contains user.
-rwxr-xr-x | localsyncthis | 19 |
1 files changed, 15 insertions, 4 deletions
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 |