Skip to content

Commit 0919ec2

Browse files
authored
feat: copy github permalinks (#33)
1 parent 9830ccb commit 0919ec2

6 files changed

Lines changed: 26 additions & 0 deletions

File tree

lazy-lock.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"friendly-snippets": { "branch": "main", "commit": "00ba9dd3df89509f95437b8d595553707c46d5ea" },
1515
"fzf": { "branch": "master", "commit": "e76aa37fd402f994ff194a02e47576fba928e8f4" },
1616
"fzf.vim": { "branch": "master", "commit": "ec75ffbfd50630bf2b8d444d89487e149bacf7f3" },
17+
"gitlinker.nvim": { "branch": "master", "commit": "cc59f732f3d043b626c8702cb725c82e54d35c25" },
1718
"gitsigns.nvim": { "branch": "main", "commit": "863903631e676b33e8be2acb17512fdc1b80b4fb" },
1819
"image.nvim": { "branch": "master", "commit": "88e9693e188b8464b1c426aebb4389fd9db2fcbf" },
1920
"indent-blankline.nvim": { "branch": "master", "commit": "18603eb949eba08300799f64027af11ef922283f" },

lua/custom/keymaps.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ K.GIT_HUNK_PREVIEW = lead .. 'ghp'
6868
K.GIT_LINE_BLAME = lead .. 'ghb'
6969
K.GIT_TOGGLE_BLAME = lead .. 'gtb'
7070
K.GIT_TOGGLE_SHOW_DELETED = lead .. 'gtd'
71+
K.GIT_COPY_PERMALINK = lead .. 'gy'
7172

7273
--- GitHub
7374
K.GITHUB_ = lead .. 'G'

lua/mikesposito/main/configs/git.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ return {
1313

1414
-- GitHub PRs, issues and reviews
1515
require 'mikesposito.main.configs.plugins.octo',
16+
17+
-- Git permalinks
18+
require 'mikesposito.main.configs.plugins.gitlinker',
1619
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
return {
2+
'ruifm/gitlinker.nvim',
3+
dependencies = {
4+
'nvim-lua/plenary.nvim',
5+
},
6+
config = function()
7+
require('gitlinker').setup {
8+
mappings = nil,
9+
}
10+
end,
11+
}

lua/mikesposito/main/settings/keymaps.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ n(K.GIT_HUNK_PREVIEW, gitsigns.preview_hunk, { desc = 'preview git hunk' })
8989
n(K.GIT_LINE_BLAME, gitsigns.blame_line, { desc = 'git blame line' })
9090
n(K.GIT_TOGGLE_BLAME, gitsigns.toggle_current_line_blame, { desc = 'toggle git blame line' })
9191
n(K.GIT_TOGGLE_SHOW_DELETED, gitsigns.toggle_deleted, { desc = 'toggle git show deleted' })
92+
n(K.GIT_COPY_PERMALINK, function()
93+
git.copy_permalink 'n'
94+
end, { desc = '[Y]ank permalink' })
95+
v(K.GIT_COPY_PERMALINK, function()
96+
git.copy_permalink 'v'
97+
end, { desc = '[Y]ank permalink' })
9298

9399
-- GitHub keymaps
94100
label(K.GITHUB_, '[G]ithub')

lua/mikesposito/main/snippets/git.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ Git.reset_hunk = function()
2222
gitsigns.reset_hunk { vim.fn.line '.', vim.fn.line 'v' }
2323
end
2424

25+
Git.copy_permalink = function(mode)
26+
require('gitlinker').get_buf_range_url(mode, { action_callback = require('gitlinker.actions').copy_to_clipboard })
27+
end
28+
2529
return Git

0 commit comments

Comments
 (0)