Skip to content

Commit 198cc40

Browse files
fix: custom browse command (#75)
1 parent d11e136 commit 198cc40

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ Enable `show_builtin_git_pickers` to additionally show builtin git pickers.
136136
```lua
137137
{
138138
-- Browse command to open commits in browser. Default fugitive GBrowse.
139-
browse_command = "GBrowse",
139+
-- {commit_hash} is the placeholder for the commit hash.
140+
browse_command = "GBrowse {commit_hash}",
141+
-- when {commit_hash} is not provided, the commit will be appended to the specified command seperated by a space
142+
-- browse_command = "GBrowse",
143+
-- => both will result in calling `:GBrowse commit`
144+
140145
-- fugitive or diffview
141146
diff_plugin = "fugitive",
142147
-- customize git in previewer

lua/advanced_git_search/actions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ end
5555
---General action: Open commit in browser
5656
---@param commit_hash string
5757
M.open_in_browser = function(commit_hash)
58-
vim.api.nvim_command(":" .. config.get_browse_command() .. commit_hash)
58+
vim.api.nvim_command(":" .. config.get_browse_command(commit_hash))
5959
end
6060

6161
---General action: Checkout commit

lua/advanced_git_search/telescope/mappings/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ local open_commit_in_browser = function(prompt_bufnr)
3434
actions.close(prompt_bufnr)
3535
local selection = action_state.get_selected_entry()
3636

37-
vim.api.nvim_command(":GBrowse " .. selection.opts.commit_hash)
37+
global_actions.open_in_browser(selection.opts.commit_hash)
3838
end
3939

4040
--- Open browser at commmit (from entry) with <C-o>

lua/advanced_git_search/utils/config.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ local config = {}
55
M.setup = function(ext_config)
66
ext_config = ext_config or {}
77

8-
ext_config.browse_command = ext_config.browse_command or "GBrowse"
8+
ext_config.browse_command = ext_config.browse_command
9+
or "GBrowse {commit_hash}"
910
ext_config.diff_plugin = ext_config.diff_plugin or "fugitive"
1011
ext_config.git_diff_flags = ext_config.git_diff_flags or {}
1112
ext_config.show_builtin_git_pickers = ext_config.show_builtin_git_pickers
@@ -165,8 +166,15 @@ M.show_builtin_git_pickers = function()
165166
return config["show_builtin_git_pickers"]
166167
end
167168

168-
M.get_browse_command = function()
169-
return config["browse_command"]
169+
M.get_browse_command = function(commit_hash)
170+
local cmd = config["browse_command"]
171+
local commit_pattern = "%{commit_hash%}"
172+
173+
if string.find(config["browse_command"], commit_pattern) == nil then
174+
return cmd .. " " .. commit_hash
175+
end
176+
177+
return string.gsub(cmd, commit_pattern, commit_hash)
170178
end
171179

172180
return M

0 commit comments

Comments
 (0)