Skip to content

Instantly share code, notes, and snippets.

@mfischer-zd
Created March 22, 2013 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfischer-zd/5219325 to your computer and use it in GitHub Desktop.
Save mfischer-zd/5219325 to your computer and use it in GitHub Desktop.
Copy briefcase files before ssh
__SSH=$(type -path ssh 2>/dev/null);
function ssh()
{
# This function overrides ssh to rsync all files listed in $HOME/.briefcase to
# the remote server before logging in. It tries very hard to skip this if
# you're logging in as another user, but it cannot detect whether you have an
# alternate "User" defined in $HOME/.ssh/config or its /etc equivalent.
# USE WITH CAUTION!
local skip_sync;
if ! type -f rsync 2>&1 >/dev/null; then
# we don't have rsync.
skip_sync=1;
fi
if [ ! -f "$HOME/.briefcase" ]; then
skip_sync=1;
fi
# skip ssh options to find hostname
while getopts ":1246AaCfgKkMNnqsTtVvXxYyb:c:D:e:F:i:L:l:m:O:o:p:R:S:w:" Option; do
if [ "$Option" = "l" ]; then
# don't sync if we're logging into a different user's account
skip_sync=1;
break;
fi
done
server=`eval echo "$"$OPTIND`
# reset $OPTIND so that subsequent invocations work properly
OPTIND=1;
if echo "$server" | grep "@"; then
# don't sync if we're logging into a different user's account
skip_sync=1;
fi
if [ -z "$skip_sync" -a -z "$DISABLE_BRIEFCASE" ]; then
rsync -vurptgoDL -e ssh --files-from="$HOME/.briefcase" "$HOME" "$server":
fi
$__SSH "$@";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment