diff --git a/config/nvim/lazy-lock.json b/config/nvim/lazy-lock.json index 1b6cfdc..8211c15 100644 --- a/config/nvim/lazy-lock.json +++ b/config/nvim/lazy-lock.json @@ -2,9 +2,7 @@ "blink.cmp": { "branch": "main", "commit": "4b18c32adef2898f95cdef6192cbd5796c1a332d" }, "cp.nvim": { "branch": "main", "commit": "029ea125b97320ff5c2884bf84bf5aa4e7077c79" }, "dial.nvim": { "branch": "master", "commit": "f2634758455cfa52a8acea6f142dcd6271a1bf57" }, - "diffs.nvim": { "branch": "main", "commit": "330e2bc9b89ebcc52b77a9fa960541c0cfbca81d" }, "fzf-lua": { "branch": "main", "commit": "fb8c50ba62a0daa433b7ac2b78834f318322b879" }, - "guard-collection": { "branch": "main", "commit": "ea1d770284473bc4976a787d61d5eb781a87d899" }, "guard.nvim": { "branch": "main", "commit": "addb8d2f40662b8b62d60dd7d18f503beb2332e7" }, "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, "lazydev.nvim": { "branch": "main", "commit": "5231c62aa83c2f8dc8e7ba957aa77098cda1257d" }, @@ -24,7 +22,6 @@ "nvim-vtsls": { "branch": "main", "commit": "0b5f73c9e50ce95842ea07bb3f05c7d66d87d14a" }, "oil.nvim": { "branch": "master", "commit": "f55b25e493a7df76371cfadd0ded5004cb9cd48a" }, "overseer.nvim": { "branch": "master", "commit": "392093e610333c0aea89bf43de7362e25783eada" }, - "snacks.nvim": { "branch": "main", "commit": "fe7cfe9800a182274d0f868a74b7263b8c0c020b" }, "treesj": { "branch": "main", "commit": "186084dee5e9c8eec40f6e39481c723dd567cb05" }, "typst-preview.nvim": { "branch": "master", "commit": "e123a7ab64e52d836e00dea9251e85b201f38966" }, "vim-abolish": { "branch": "master", "commit": "dcbfe065297d31823561ba787f51056c147aa682" }, diff --git a/config/nvim/lua/plugins/fzf.lua b/config/nvim/lua/plugins/fzf.lua index 23181b8..9f0a830 100644 --- a/config/nvim/lua/plugins/fzf.lua +++ b/config/nvim/lua/plugins/fzf.lua @@ -40,8 +40,7 @@ return { { 'f/', 'FzfLua search_history' }, { 'f:', 'FzfLua command_history' }, { 'fa', 'FzfLua autocmds' }, - { 'fB', 'FzfLua builtin' }, - { 'fb', 'FzfLua buffers' }, + { 'fB', 'FzfLua buffers' }, { 'fc', 'FzfLua commands' }, { 'fe', @@ -69,8 +68,8 @@ return { 'fs', 'FzfLua files cwd=~/.config/nix/scripts', }, - { 'gB', 'FzfLua git_branches' }, - { 'gb', 'FzfLua git_worktrees' }, + { 'gb', 'FzfLua git_branches' }, + { 'gw', 'FzfLua git_worktrees' }, { 'gq', 'FzfLua quickfix' }, { 'gl', 'FzfLua loclist' }, }, diff --git a/config/nvim/lua/plugins/git.lua b/config/nvim/lua/plugins/git.lua index 8713bdb..f62d97e 100644 --- a/config/nvim/lua/plugins/git.lua +++ b/config/nvim/lua/plugins/git.lua @@ -1,3 +1,58 @@ +---@return string +local function gh_file_loc() + local root = vim.trim(vim.fn.system('git rev-parse --show-toplevel')) + local file = vim.api.nvim_buf_get_name(0):sub(#root + 2) + local mode = vim.fn.mode() + if mode:match('[vV]') or mode == '\22' then + local s = vim.fn.line('v') + local e = vim.fn.line('.') + if s > e then + s, e = e, s + end + if s == e then + return ('%s:%d'):format(file, s) + end + return ('%s:%d-%d'):format(file, s, e) + end + return ('%s:%d'):format(file, vim.fn.line('.')) +end + +---@param args string[] +local function gh_yank(args) + vim.system(args, { text = true }, function(result) + if result.code == 0 then + local url = vim.trim(result.stdout or '') + if url ~= '' then + vim.schedule(function() + vim.fn.setreg('+', url) + end) + end + end + end) +end + +---@param kind 'issue'|'pr' +---@param state 'all'|'open'|'closed' +local function gh_picker(kind, state) + local next_state = ({ all = 'open', open = 'closed', closed = 'all' })[state] + local label = kind == 'pr' and 'PRs' or 'Issues' + require('fzf-lua').fzf_exec(('gh %s list --limit 100 --state %s'):format(kind, state), { + prompt = ('%s (%s)> '):format(label, state), + header = ':: to toggle all/open/closed', + actions = { + ['default'] = function(selected) + local num = selected[1]:match('^(%d+)') + if num then + vim.system({ 'gh', kind, 'view', num, '--web' }) + end + end, + ['ctrl-o'] = function() + gh_picker(kind, next_state) + end, + }, + }) +end + return { { 'tpope/vim-fugitive', @@ -8,7 +63,6 @@ return { enabled = true, init = function() vim.g.diffs = { - -- debug = '/tmp/diffs.log', filetypes = { 'fugitive', 'git', 'gitcommit', 'diff' }, hide_prefix = true, highlights = { @@ -24,14 +78,48 @@ return { end, }, { - -- TODO: find out a way to remove this/better overall github integration - 'folke/snacks.nvim', - ---@type snacks.Config - opts = { gitbrowse = {} }, + 'ibhagwan/fzf-lua', keys = { - { 'go', 'lua Snacks.gitbrowse()' }, - { 'gi', 'lua Snacks.picker.gh_issue()' }, - { 'gp', 'lua Snacks.picker.gh_pr()' }, + { + 'go', + function() + local branch = vim.trim(vim.fn.system('git branch --show-current')) + vim.system({ 'gh', 'browse', gh_file_loc(), '--branch', branch }) + end, + mode = { 'n', 'v' }, + }, + { + 'gy', + function() + gh_yank({ 'gh', 'browse', gh_file_loc(), '--commit=last', '-n' }) + end, + mode = { 'n', 'v' }, + }, + { + 'gl', + function() + gh_yank({ 'gh', 'browse', gh_file_loc(), '-n' }) + end, + mode = { 'n', 'v' }, + }, + { + 'gx', + function() + vim.system({ 'gh', 'browse' }) + end, + }, + { + 'gi', + function() + gh_picker('issue', 'all') + end, + }, + { + 'gp', + function() + gh_picker('pr', 'all') + end, + }, }, }, }