Last active
August 29, 2015 13:57
-
-
Save alexmchale/9915238 to your computer and use it in GitHub Desktop.
A post-commit hook for Git to print (and copy to clipboard on OSX) the likely GitHub URL for the commit
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
#!/usr/bin/env ruby | |
=begin | |
This hook will print the likely GitHub URL for each new commit. | |
Install this hook with wget: | |
wget 'https://gist.githubusercontent.com/alexmchale/9915238/raw/post-commit' -O .git/hooks/post-commit; chmod u+x .git/hooks/post-commit | |
Install this hook with curl: | |
curl 'https://gist.githubusercontent.com/alexmchale/9915238/raw/post-commit' > .git/hooks/post-commit; chmod u+x .git/hooks/post-commit | |
=end | |
require "shellwords" | |
revision = `git log --pretty=oneline -1 HEAD | cut -d ' ' -f 1` | |
(_, username, repository) = `git remote -v | grep github.com | head -1`.match(%r|github.com[:/](.*?)/(.*?).git|).to_a | |
url = "https://github.com/#{ username }/#{ repository }/commit/#{ revision }" | |
escaped_url = Shellwords.escape(url) | |
system "echo #{ escaped_url } | /usr/bin/pbcopy general" if File.executable? "/usr/bin/pbcopy" | |
puts | |
puts url | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment