mirror of
https://github.com/adusak/bitbucket-git-helpers.plugin.zsh.git
synced 2026-01-11 19:30:23 +01:00
41 lines
1.0 KiB
Ruby
Executable File
41 lines
1.0 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
#
|
|
# Open a file/directory on bitbucket in the current branch
|
|
#
|
|
# Copyright 2016 Joe Block <jpb@unixorn.net>
|
|
#
|
|
# License: Apache 2.0, see LICENSE in this repository.
|
|
|
|
require 'pathname'
|
|
require_relative 'bbhelpers'
|
|
|
|
def constructURL
|
|
remote = git_remote()
|
|
bbloc = remote.index('bitbucket.org')
|
|
if not bbloc
|
|
host = repo_url
|
|
else
|
|
host = remote[bbloc..-5].sub(':','/')
|
|
end
|
|
url_prefix="https://#{host}/src/#{git_commit}"
|
|
root = Pathname.new(git_root())
|
|
pwd = Pathname.new(Dir.pwd())
|
|
if ARGV.length == 1
|
|
path = "/#{pwd.relative_path_from(root).to_s()}/#{ARGV[0]}"
|
|
else
|
|
if Dir.pwd() == git_root()
|
|
path = ''
|
|
else
|
|
path = "/#{pwd.relative_path_from(root).to_s()}"
|
|
end
|
|
end
|
|
url = url_prefix + path + "?at=#{git_branch}"
|
|
end
|
|
|
|
if ARGV.length > 1
|
|
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'
|
|
end
|
|
|
|
openURL(constructURL())
|