Skip to content

Commit

Permalink
feat: add gh commit feature
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwoodward committed May 10, 2024
1 parent 12668da commit 9e253dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ A small Neovim wrapper around the GitHub CLI `gh browse` tool to enable fast sha
The plugin defines commands that wrap the functionality of zoxide:

- `:GithubBrowseRepo`: Opens the current GitHub repository in your default web browser.
- `:GithubBrowseToLine`: Opens the current GitHub repository in your default web browser.
- `:GithubBrowseLine`: Opens the current GitHub repository in your default web browser.
- `:GithubBrowseCommit`: Opens given commit in GitHub in your default web browser.

## Demo

Expand Down
14 changes: 13 additions & 1 deletion lua/github-browse/browse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ M.browse_repo = function()
execute_command("browse")
end

---@param commit string
M.browse_commit = function(commit)
vim.fn.jobstart({ "gh", "browse", commit })
end

--- Open file and line number under the course in your browser.
M.browse_to_line = function()
M.browse_line = function()
-- local start_pos = vim.fn.line("v")
-- local end_pos = vim.fn.line(".")
-- local start_pos = vim.api.nvim_buf_get_mark(0, "<") ---@type number[]
-- local end_pos = vim.api.nvim_buf_get_mark(0, ">") ---@type number[]
-- print(start_pos)
-- print(end_pos)

local cursor_pos, _ = unpack(vim.api.nvim_win_get_cursor(0))
local file = vim.fn.expand("%:.")

Expand Down
3 changes: 2 additions & 1 deletion plugin/github-browse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ vim.g.loaded_github_browse = 1
-- Be careful to not overuse this file!
local gh = require("github-browse.browse")
vim.api.nvim_create_user_command("GithubBrowseRepo", gh.browse_repo, {})
vim.api.nvim_create_user_command("GithubBrowseToLine", gh.browse_to_line, {})
vim.api.nvim_create_user_command("GithubBrowseLine", gh.browse_line, {})
vim.api.nvim_create_user_command("GithubBrowseCommit", gh.browse_commit, {})

0 comments on commit 9e253dd

Please sign in to comment.