1
0
Fork 0

nvim: very basic glab integration

This commit is contained in:
Daniel Kempkens 2024-04-22 23:14:48 +02:00
parent 7e0645978e
commit 4aae815264
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
4 changed files with 52 additions and 3 deletions

View file

@ -198,6 +198,7 @@
]; ];
TREEFMT_CONFIG_FILE = config.treefmt.build.configFile; TREEFMT_CONFIG_FILE = config.treefmt.build.configFile;
REMOTE_REPO_TYPE = "forgejo";
}; };
}; };
}; };

View file

@ -11,6 +11,7 @@
neogit (require :neogit) neogit (require :neogit)
wk (require :which-key) wk (require :which-key)
repl (require :nifoc.repl) repl (require :nifoc.repl)
repo (require :nifoc.repo)
formatting (require :nifoc.formatting)] formatting (require :nifoc.formatting)]
(fn mod.setup [] (fn mod.setup []
(keymap.set :n :<space> :<nop> {:noremap true}) (keymap.set :n :<space> :<nop> {:noremap true})
@ -43,6 +44,9 @@
(keymap.set :n :<leader>vl #(gitsigns.blame_line {:full true}) (keymap.set :n :<leader>vl #(gitsigns.blame_line {:full true})
{:desc "Blame Line"}) {:desc "Blame Line"})
(keymap.set :n :<leader>vd :<cmd>DiffviewOpen<CR> {:desc "Open DiffView"}) (keymap.set :n :<leader>vd :<cmd>DiffviewOpen<CR> {:desc "Open DiffView"})
(keymap.set :n :<leader>vvr #(repo.open-repo) {:desc "Open repository"})
(keymap.set :n :<leader>vvm #(repo.open-merge-request) {:desc "Open MR"})
(keymap.set :n :<leader>vvc #(repo.open-ci) {:desc "Open CI"})
(keymap.set :n :<leader>lk telescope-builtin.keymaps (keymap.set :n :<leader>lk telescope-builtin.keymaps
{:desc "Show Keymappings"}) {:desc "Show Keymappings"})
(keymap.set :n :<leader>ld #(telescope-builtin.diagnostics telescope-ivy) (keymap.set :n :<leader>ld #(telescope-builtin.diagnostics telescope-ivy)

View file

@ -0,0 +1,33 @@
(let [mod {}
wezterm (require :wezterm)]
(fn exe [bin] (vim.fn.exepath bin))
(fn open-split [program]
(let [args [:cli :split-pane :--bottom :--percent :60 "--"]]
(each [_ value (ipairs program)]
(table.insert args value))
(wezterm.exec args
(fn [result]
(when (not= result.code 0)
(vim.notify "wezterm: Error opening split window"
vim.log.levels.ERROR []))))))
(fn mod.open-repo []
(case vim.env.REMOTE_REPO_TYPE
:github nil
:gitlab (vim.system [:glab :repo :view :--web])
:forgejo nil))
(fn mod.open-merge-request []
(case vim.env.REMOTE_REPO_TYPE
:github nil
:gitlab (vim.system [:glab :mr :view :--web])
:forgejo nil))
(fn mod.open-ci []
(case vim.env.REMOTE_REPO_TYPE
:github nil
:gitlab (open-split [(exe :glab) :pipeline :ci :view])
:forgejo nil))
mod)

View file

@ -7,6 +7,7 @@
web-devicons (require :nvim-web-devicons) web-devicons (require :nvim-web-devicons)
colors (. (require :nifoc.theme) :colors) colors (. (require :nifoc.theme) :colors)
formatting (require :nifoc.formatting) formatting (require :nifoc.formatting)
repo (require :nifoc.repo)
nifoc-treesitter (require :nifoc.treesitter) nifoc-treesitter (require :nifoc.treesitter)
navic (require :nvim-navic) navic (require :nvim-navic)
neogit (require :neogit)] neogit (require :neogit)]
@ -150,6 +151,11 @@
;; git ;; git
(set mod.git (set mod.git
{:condition heirline-conditions.is_git_repo {:condition heirline-conditions.is_git_repo
:static {:git-repo-type vim.env.REMOTE_REPO_TYPE
:git-repo-icon {:github " " :gitlab " " :forgejo ""}
:git-repo-color {:github "#f6f8fa"
:gitlab "#d15232"
:forgejo "#c22d15"}}
:init (fn [self] :init (fn [self]
(let [git-status vim.b.gitsigns_status_dict] (let [git-status vim.b.gitsigns_status_dict]
(set self.git-head git-status.head) (set self.git-head git-status.head)
@ -167,11 +173,16 @@
:callback #(neogit.open {:kind :split})} :callback #(neogit.open {:kind :split})}
:hl {:fg colors.black :bg colors.orange :bold true}} :hl {:fg colors.black :bg colors.orange :bold true}}
3 mod.space 3 mod.space
4 {:provider #(.. " " $1.git-added " ") 4 {:condition #(not= $1.git-repo-type nil)
:provider #(.. (. $1.git-repo-icon $1.git-repo-type) " ")
:on_click {:name :heirline_git_repo_type
:callback #(repo.open-repo)}
:hl #{:fg (. $1.git-repo-color $1.git-repo-type)}}
5 {:provider #(.. " " $1.git-added " ")
:hl {:fg colors.bright_green}} :hl {:fg colors.bright_green}}
5 {:provider #(.. " " $1.git-removed " ") 6 {:provider #(.. " " $1.git-removed " ")
:hl {:fg colors.bright_red}} :hl {:fg colors.bright_red}}
6 {:provider #(.. " " $1.git-changed) :hl {:fg colors.cyan}}}) 7 {:provider #(.. " " $1.git-changed) :hl {:fg colors.cyan}}})
;; Diagnostics ;; Diagnostics
(set mod.diagnostics {:condition heirline-conditions.has_diagnostics (set mod.diagnostics {:condition heirline-conditions.has_diagnostics
:init (fn [self] :init (fn [self]