Last active
March 22, 2018 16:07
-
-
Save jeffreymeng/ef9699a2bfae3ae577f8c2d0d4a4495b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
BASE_PATH="UNKNOWN - edit this by changing the variable in the gitsync file." | |
if [ "$#" == 0 ] | |
then | |
echo "Gitsync: Invalid Usage. See gitsync --help for more information" | |
elif [ "$1" == "--help" ] || [ "$1" == "--usage" ] | |
then | |
echo " | |
usage: gitsync [--help] [--usage] | |
returns help page | |
OR | |
gitsync <directory> <commit message> | |
Gitsync is a tool to help you automatically commit in github. | |
Essenally, it runs the following git commands | |
git status | |
git add --all . | |
git commit | |
git push | |
The first argument passed should be the path, relative to the base path. | |
Your base path is: $BASE_PATH | |
You can configure the base path in the source of this command. | |
To commit, enter gitsync, and then 't'(this) for the current directrory, or a directory path(encapsulated in quotes if there are spaces in the path). | |
All parameters after the first will be combined into the git commit message. The spaces will be kept. | |
Example 1: | |
$ pwd | |
> /Users/username/documents/some_git_repo | |
$ gitsync t bug fix | |
The above command would create a commit, with the summary 'bug fix'. | |
You could also repeat the above when you are not in the repo | |
Example 2: | |
$ pwd | |
> /some_random_directory/ | |
$ gitsync /Users/username/documents/some_git_repo bug fix | |
The above command would do the same thing as the first example, but the current directory would not matter. Instead, it will commit from <basepath>/<argument 1>. | |
Example 3: | |
$ pwd | |
> /some_random_directory/ | |
$ gitsync '/Users/username/documents/some_git_repo with_a_space_in_the_path_name' bug fix | |
If your command path has a space, you need to encapsulate the entire path name in quotes, otherwise your | |
input will be interpreted as: | |
IN /Users/username/documents/some_git_repo | |
COMMIT WITH MESSAGE with_a_space_in_the_path_name bug fix | |
Instead of the desired result of: | |
IN /Users/username/documents/some_git_repo with_a_space_in_the_path_name | |
COMMIT WITH MESSAGE bug fix | |
" | |
exit 1 | |
elif [ $1 == "t" ] | |
then | |
git status | |
git add --all . | |
git commit -m "${*:2}" | |
git push | |
echo "github sync sucussful" | |
exit 1 | |
else | |
echo "Swiching to directory: $BASE_PATH$1" | |
cd "$BASE_PATH$1" | |
echo "Current directory:" | |
pwd | |
git status | |
git add --all . | |
git commit -m "${*:2}" | |
git push | |
echo "github sync successful" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment