Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(picker): add config options for changing mappings #448

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ require"octo".setup({
enable_builtin = false, -- shows a list of builtin actions when no action is provided
default_remote = {"upstream", "origin"}; -- order to try remotes
ssh_aliases = {}, -- SSH aliases. e.g. `ssh_aliases = {["github.aaakk.us.kg-work"] = "github.com"}`
picker_config = {
mappings = {
open_in_browser = { lhs = "<C-b>", desc = "open issue in browser" },
copy_url = { lhs = "<C-y>", desc = "copy url to system clipboard" },
checkout_pr = { lhs = "<C-o>", desc = "checkout pull request" },
merge_pr = { lhs = "<C-r>", desc = "merge pull request" },
},
},
reaction_viewer_hint_icon = ""; -- marker for user reactions
user_icon = " "; -- user icon
timeline_marker = ""; -- timeline marker
Expand Down
6 changes: 6 additions & 0 deletions lua/octo/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ M.defaults = {
picker = "telescope",
picker_config = {
use_emojis = false,
mappings = {
open_in_browser = { lhs = "<C-b>", desc = "open issue in browser" },
copy_url = { lhs = "<C-y>", desc = "copy url to system clipboard" },
checkout_pr = { lhs = "<C-o>", desc = "checkout pull request" },
merge_pr = { lhs = "<C-r>", desc = "merge pull request" },
},
},
default_remote = { "upstream", "origin" },
ssh_aliases = {},
Expand Down
22 changes: 12 additions & 10 deletions lua/octo/pickers/telescope/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ function M.issues(opts)
action_set.select:replace(function(prompt_bufnr, type)
open(type)(prompt_bufnr)
end)
map("i", "<c-b>", open_in_browser())
map("i", "<c-y>", copy_url())
map("i", cfg.picker_config.mappings.open_in_browser.lhs, open_in_browser())
map("i", cfg.picker_config.mappings.copy_url.lhs, copy_url())
return true
end,
})
Expand Down Expand Up @@ -315,10 +315,10 @@ function M.pull_requests(opts)
action_set.select:replace(function(prompt_bufnr, type)
open(type)(prompt_bufnr)
end)
map("i", "<c-o>", checkout_pull_request())
map("i", "<c-b>", open_in_browser())
map("i", "<c-y>", copy_url())
map("i", "<c-r>", merge_pull_request())
map("i", cfg.picker_config.mappings.checkout_pr.lhs, checkout_pull_request())
map("i", cfg.picker_config.mappings.open_in_browser.lhs, open_in_browser())
map("i", cfg.picker_config.mappings.copy_url.lhs, copy_url())
map("i", cfg.picker_config.mappings.merge_pr.lhs, merge_pull_request())
return true
end,
})
Expand Down Expand Up @@ -479,6 +479,7 @@ end
---
function M.search(opts)
opts = opts or {}
local cfg = octo_config.get_config()
local requester = function()
return function(prompt)
if not opts.prompt and utils.is_blank(prompt) then
Expand Down Expand Up @@ -531,8 +532,8 @@ function M.search(opts)
action_set.select:replace(function(prompt_bufnr, type)
open(type)(prompt_bufnr)
end)
map("i", "<c-b>", open_in_browser())
map("i", "<c-y>", copy_url())
map("i", cfg.picker_config.mappings.open_in_browser.lhs, open_in_browser())
map("i", cfg.picker_config.mappings.copy_url.lhs, copy_url())
return true
end,
})
Expand Down Expand Up @@ -923,6 +924,7 @@ end
--
function M.repos(opts)
opts = opts or {}
local cfg = octo_config.get_config()
if not opts.login then
if vim.g.octo_viewer then
opts.login = vim.g.octo_viewer
Expand Down Expand Up @@ -967,8 +969,8 @@ function M.repos(opts)
action_set.select:replace(function(prompt_bufnr, type)
open(type)(prompt_bufnr)
end)
map("i", "<c-b>", open_in_browser())
map("i", "<c-y>", copy_url())
map("i", cfg.picker_config.mappings.open_in_browser.lhs, open_in_browser())
map("i", cfg.picker_config.mappings.copy_url.lhs, copy_url())
return true
end,
})
Expand Down