Refactor out some functions I'm going to use in other git-bb-* scripts

This commit is contained in:
Joe Block
2016-04-08 09:08:48 -07:00
parent fc991a4909
commit 93b73c3964
2 changed files with 43 additions and 28 deletions

34
bin/bbhelpers.rb Normal file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/env ruby
#
# Copyright 2016 Joe Block <jpb@unixorn.net>
#
# License: Apache 2.0, see LICENSE in this repository.
#
# Helper functions that are common across the git-bb-* scripts. Admittedly
# not very pretty.
def git_branch
`git rev-parse --abbrev-ref HEAD`.chomp
end
def git_commit
`git rev-parse HEAD`.chomp
end
def git_remote
`git config --get remote.origin.url`.chomp
end
def git_root
`git rev-parse --show-toplevel`.chomp
end
def openURL(url)
if RUBY_PLATFORM.index('darwin')
open_command = 'open'
end
if RUBY_PLATFORM.index('linux')
open_command = 'xdg-open'
end
system("#{open_command} #{url}")
end