mirror of
https://github.com/adusak/bitbucket-git-helpers.plugin.zsh.git
synced 2026-03-24 10:21:07 +01:00
Refactor out some functions I'm going to use in other git-bb-* scripts
This commit is contained in:
34
bin/bbhelpers.rb
Normal file
34
bin/bbhelpers.rb
Normal 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
|
||||||
@@ -4,31 +4,22 @@
|
|||||||
#
|
#
|
||||||
# Copyright 2016 Joe Block <jpb@unixorn.net>
|
# Copyright 2016 Joe Block <jpb@unixorn.net>
|
||||||
#
|
#
|
||||||
# License: Apache 2.0
|
# License: Apache 2.0, see LICENSE in this repository.
|
||||||
|
|
||||||
|
def push_loadpath
|
||||||
|
$: << File.expand_path(File.dirname(caller.first))
|
||||||
|
end
|
||||||
|
|
||||||
|
push_loadpath
|
||||||
|
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
require 'bbhelpers'
|
||||||
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 constructURL
|
def constructURL
|
||||||
remote = git_remote()
|
remote = git_remote()
|
||||||
bbloc = remote.index('bitbucket.org')
|
bbloc = remote.index('bitbucket.org')
|
||||||
if not bbloc
|
if not bbloc
|
||||||
"This repo does not have a fetch remote at bitbucket"
|
"git-bb-open only works for repositories with their origin remote on bitbucket.org"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
url_prefix="https://#{remote[bbloc..-5]}/src/#{git_commit}"
|
url_prefix="https://#{remote[bbloc..-5]}/src/#{git_commit}"
|
||||||
@@ -46,16 +37,6 @@ def constructURL
|
|||||||
url = url_prefix + path + "?at=#{git_branch}"
|
url = url_prefix + path + "?at=#{git_branch}"
|
||||||
end
|
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
|
|
||||||
|
|
||||||
if ARGV.length > 1
|
if ARGV.length > 1
|
||||||
puts 'Usage: git-bb-open without args to open the current directory on bitbucket, viewing the current branch.'
|
puts 'Usage: git-bb-open without args to open the current directory on bitbucket, viewing the current branch.'
|
||||||
puts ' git-bb-open <path> to open <path> on bitbucket, viewing the current branch'
|
puts ' git-bb-open <path> to open <path> on bitbucket, viewing the current branch'
|
||||||
|
|||||||
Reference in New Issue
Block a user