Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 47 lines (39 sloc) 1.297 kb
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored
1 #!/bin/sh
32e7bec @jamiew push: --set-upstream while pushing (same as -u)
authored
2 #
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored
3 # Usage: push
4 #
5daed4f @jamiew Cleanup commentary
authored
5 # Send your local branch changes to the remote branch,
6 # and copy the relevant GitHub 'compare' URL to your clipboard (!)
7 # This is Mac-only for the time being
b67805d @jamiew push: extra args will be passed through, e.g. 'push -f'
authored
8 #
9 # Any extra args to this command will be passed through to 'git push',
10 # e.g. for doing "push -f"
32e7bec @jamiew push: --set-upstream while pushing (same as -u)
authored
11 #
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored
12
13 remote=origin
14 branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
15
1524355 @jamiew Pimp out push for clipboard action
authored
16 # Push & save output
32e7bec @jamiew push: --set-upstream while pushing (same as -u)
authored
17 push=$(git push --set-upstream $* $remote $branch 2>&1)
1524355 @jamiew Pimp out push for clipboard action
authored
18 exit_code=$?
19 if [ $exit_code != 0 ]; then
20 echo "Ouch, push failed! code=$exit_code, output=$push"
21 exit $exit_code
22 fi
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored
23
1524355 @jamiew Pimp out push for clipboard action
authored
24 # Cleanly exit if nothing was pushed
25 if echo $push | grep "Everything up-to-date" >/dev/null; then
26 echo "git says everything is up-to-date! "
27 exit 0
28 fi
29
579fdd8 @jamiew push: smarter pbcopy command detection, cleaner output
authored
30 # Show git's output
1524355 @jamiew Pimp out push for clipboard action
authored
31 echo $push
579fdd8 @jamiew push: smarter pbcopy command detection, cleaner output
authored
32
33 # Parse output into sexy GitHub compare URL!
3b50193 @jamiew Fully pimped push command, featuring smart GitHub clipboard-copy URL
authored
34 remote_url=$(git remote show $remote -n | grep Push | awk '{ print $3 }')
9a5e199 @jamiew Fix if/not if
authored
35 if [[ "$remote_url" =~ "github.com" ]]; then
fc39ebd @jamiew push: only copy GitHub compare url if remote is on GitHub
authored
36 repo_name=$(echo $remote_url | sed 's/.*\:\(.*\)\.git/\1/')
37 refs=$(echo $push | awk '{ print $3}' | sed 's/\.\./\.\.\./')
1524355 @jamiew Pimp out push for clipboard action
authored
38
fc39ebd @jamiew push: only copy GitHub compare url if remote is on GitHub
authored
39 github_url="https://github.com/$repo_name/compare/$refs"
40 which -s pbcopy && echo $github_url | pbcopy && echo "Compare URL copied to clipboard!"
41 # which -s open && open -g $github_url
42 echo $github_url
3b50193 @jamiew Fully pimped push command, featuring smart GitHub clipboard-copy URL
authored
43
fc39ebd @jamiew push: only copy GitHub compare url if remote is on GitHub
authored
44 echo
45 fi
1524355 @jamiew Pimp out push for clipboard action
authored
46 exit 0
Something went wrong with that request. Please try again.