mirror of
https://github.com/jessebot/dot_files.git
synced 2025-10-01 01:48:43 +00:00
update GitUrl to work better with github
This commit is contained in:
parent
dc5a8e9a39
commit
7c57103793
2 changed files with 31 additions and 12 deletions
|
@ -67,4 +67,4 @@ require('user.completion')
|
|||
require('user.nvim-colorizer')
|
||||
|
||||
-- experiment to give you a remote git permalink URL for your your current line
|
||||
-- require('user.git_url')
|
||||
require('user.git_url')
|
||||
|
|
|
@ -6,28 +6,47 @@ local function get_git_url()
|
|||
-- split into git@github.com and jessebot/onboardme.git
|
||||
local base_domain, owner_repo = string.match(remote_origin, "(.*):(.*)")
|
||||
|
||||
print(base_domain)
|
||||
|
||||
-- this only works on github right now
|
||||
if string.find(base_domain, "github") then
|
||||
-- get the name of the current opened file
|
||||
local current_file = vim.fn.expand('%:p')
|
||||
if string.find(base_domain, "github.com") then
|
||||
local gh_url = "https://github.com/"
|
||||
|
||||
-- git repo root directory
|
||||
local git_root_dir = vim.fn.system("git rev-parse --show-toplevel")
|
||||
remote_file_path = current_file:gsub(git_root_dir, "")
|
||||
print(remote_file_path)
|
||||
|
||||
local git_root_dir = vim.fn.system("git rev-parse --show-prefix"):gsub("[\n\r]", " ")
|
||||
-- get the name of the current opened file
|
||||
local current_file = vim.fn.expand('%:t')
|
||||
-- get the current line number
|
||||
local current_line = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
file_line = remote_file_path .. "#L" .. current_line
|
||||
|
||||
-- combine file path, naem of file, and line number
|
||||
local file_line = git_root_dir .. current_file .. "#L" .. current_line
|
||||
file_line = string.gsub(file_line, "%s+", "")
|
||||
|
||||
-- get name of branch
|
||||
local branch = vim.fn.system("git branch --show")
|
||||
|
||||
-- changes jessebot/onboardme.git to jessebot/onboardme/blob/main/
|
||||
repo_branch_url = owner_repo:gsub(".git", "/blob/" .. branch)
|
||||
local repo_branch_url = owner_repo:gsub(".git", "/blob/" .. branch)
|
||||
|
||||
local gh_url = "https://github.com/" .. repo_branch_url .. "/" .. file_line
|
||||
-- combines https://github.com/ + jessebot/onboardme/blob/main/ + path/file.txt#1
|
||||
gh_url = gh_url .. repo_branch_url .. "/" .. file_line
|
||||
|
||||
-- remove all new lines and white space
|
||||
gh_url = string.gsub(gh_url, "%s+", "")
|
||||
gh_url = string.gsub(gh_url, "[\n\r]", "")
|
||||
|
||||
print("External git link is:")
|
||||
print(gh_url)
|
||||
end
|
||||
end
|
||||
|
||||
get_git_url()
|
||||
-- ------------------------------ open bpython -------------------------------
|
||||
-- install bpython beforehand: brew install bpython
|
||||
vim.api.nvim_create_user_command(
|
||||
'GitUrl',
|
||||
function()
|
||||
get_git_url()
|
||||
end,
|
||||
{ bang = true }
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue