Last active
November 4, 2015 03:27
-
-
Save acobster/f6acbb6b215345bedfd5 to your computer and use it in GitHub Desktop.
Grab/push specific files between a remote directory and a local Git working directory, preserving directory structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .grab/config | |
GRAB_USER='user' | |
GRAB_HOST='hostname' | |
GRAB_REMOTE_ROOT='/var/www/html/some/path' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .grab/files | |
index.php | |
some/path/foo.php | |
# graball/pushall function will grab/push both files relative to the Git root! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in your .bash_profile, add: | |
# source path/to/grab.bash | |
# Grab a file from the remote server and place it in the | |
# working directory, relative to the Git root. | |
grab() { | |
root=`git root` | |
if [ ! -f "$root/.grab/config" ] ; then | |
echo "no config found: $root/.grab/config" | |
return 1 | |
fi | |
source $root/.grab/config | |
base=$(dirname $root/$1) | |
if [[ ! -d $base ]] ; then | |
mkdir -p $base | |
fi | |
scp $GRAB_USER@$GRAB_HOST:$GRAB_REMOTE_ROOT/$1 $root/$1 | |
} | |
# Push up a file (named relative to the Git root) to the corresponding | |
# place on the remote server | |
push() { | |
root=`git root` | |
if [ ! -f "$root/.grab/config" ] ; then | |
echo "no config found: $root/.grab/config" | |
return 1 | |
fi | |
source $root/.grab/config | |
base=$(dirname $root/$1) | |
if [[ ! -d $base ]] ; then | |
mkdir -p $base | |
fi | |
scp $root/$1 $GRAB_USER@$GRAB_HOST:$GRAB_REMOTE_ROOT/$1 | |
} | |
# Grab all files listed in $root/.grab/files | |
graball() { | |
root=`git root` | |
if [ ! -f "$root/.grab/files" ] ; then | |
echo "no file list found: $root/.grab/files" | |
return 1 | |
fi | |
cat $root/.grab/files | while read file; do grab $file; done | |
} | |
# Push all files listed in $root/.grab/files | |
pushall() { | |
root=`git root` | |
if [ ! -f "$root/.grab/files" ] ; then | |
echo "no file list found: $root/.grab/files" | |
return 1 | |
fi | |
cat $root/.grab/files | while read file; do push $file; done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment