Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 42 lines (35 sloc) 1.213 kB
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored
1 #!/bin/sh
2 #
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
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored
8 #
9
10 remote=origin
11 branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
12
1524355 @jamiew Pimp out push for clipboard action
authored
13 # Push & save output
3b50193 @jamiew Fully pimped push command, featuring smart GitHub clipboard-copy URL
authored
14 push=$(git push $remote $branch 2>&1)
1524355 @jamiew Pimp out push for clipboard action
authored
15 exit_code=$?
16 if [ $exit_code != 0 ]; then
17 echo "Ouch, push failed! code=$exit_code, output=$push"
18 exit $exit_code
19 fi
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored
20
1524355 @jamiew Pimp out push for clipboard action
authored
21 # Cleanly exit if nothing was pushed
22 if echo $push | grep "Everything up-to-date" >/dev/null; then
23 echo "git says everything is up-to-date! "
24 exit 0
25 fi
26
27 # Parse output into sexy GitHub compare URL!
28 echo $push
3b50193 @jamiew Fully pimped push command, featuring smart GitHub clipboard-copy URL
authored
29 remote_url=$(git remote show $remote -n | grep Push | awk '{ print $3 }')
30 echo $remote_url
31 repo_name=$(echo $remote_url | sed 's/.*\:\(.*\)\.git/\1/')
32 echo $repo_name
33 refs=$(echo $push | awk '{ print $3}' | sed 's/\.\./\.\.\./')
1524355 @jamiew Pimp out push for clipboard action
authored
34 echo $refs
35
3b50193 @jamiew Fully pimped push command, featuring smart GitHub clipboard-copy URL
authored
36 github_url="https://github.com/$repo_name/compare/$refs"
37 echo $github_url
38 [ -n $(which pbcopy) ] && echo $github_url | pbcopy || echo "no 'pbcopy' command, skipping clipboard copy"
39 [ -n $(which open) ] && open -g $github_url || echo "no 'open' command, skipping browser open"
40
1524355 @jamiew Pimp out push for clipboard action
authored
41 exit 0
Something went wrong with that request. Please try again.