From 4aae815264f68ff6b385bf3629eedc4cc32133b6 Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Mon, 22 Apr 2024 23:14:48 +0200 Subject: [PATCH] nvim: very basic glab integration --- flake.nix | 1 + home/config/nvim/nifoc/keymap.fnl | 4 ++++ home/config/nvim/nifoc/repo.fnl | 33 +++++++++++++++++++++++++++ home/config/nvim/nifoc/statusline.fnl | 17 +++++++++++--- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 home/config/nvim/nifoc/repo.fnl diff --git a/flake.nix b/flake.nix index 502099a..8fdddda 100644 --- a/flake.nix +++ b/flake.nix @@ -198,6 +198,7 @@ ]; TREEFMT_CONFIG_FILE = config.treefmt.build.configFile; + REMOTE_REPO_TYPE = "forgejo"; }; }; }; diff --git a/home/config/nvim/nifoc/keymap.fnl b/home/config/nvim/nifoc/keymap.fnl index b590c9e..b3e31d2 100644 --- a/home/config/nvim/nifoc/keymap.fnl +++ b/home/config/nvim/nifoc/keymap.fnl @@ -11,6 +11,7 @@ neogit (require :neogit) wk (require :which-key) repl (require :nifoc.repl) + repo (require :nifoc.repo) formatting (require :nifoc.formatting)] (fn mod.setup [] (keymap.set :n : : {:noremap true}) @@ -43,6 +44,9 @@ (keymap.set :n :vl #(gitsigns.blame_line {:full true}) {:desc "Blame Line"}) (keymap.set :n :vd :DiffviewOpen {:desc "Open DiffView"}) + (keymap.set :n :vvr #(repo.open-repo) {:desc "Open repository"}) + (keymap.set :n :vvm #(repo.open-merge-request) {:desc "Open MR"}) + (keymap.set :n :vvc #(repo.open-ci) {:desc "Open CI"}) (keymap.set :n :lk telescope-builtin.keymaps {:desc "Show Keymappings"}) (keymap.set :n :ld #(telescope-builtin.diagnostics telescope-ivy) diff --git a/home/config/nvim/nifoc/repo.fnl b/home/config/nvim/nifoc/repo.fnl new file mode 100644 index 0000000..5b4b13d --- /dev/null +++ b/home/config/nvim/nifoc/repo.fnl @@ -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) diff --git a/home/config/nvim/nifoc/statusline.fnl b/home/config/nvim/nifoc/statusline.fnl index bb045f2..2775d2e 100644 --- a/home/config/nvim/nifoc/statusline.fnl +++ b/home/config/nvim/nifoc/statusline.fnl @@ -7,6 +7,7 @@ web-devicons (require :nvim-web-devicons) colors (. (require :nifoc.theme) :colors) formatting (require :nifoc.formatting) + repo (require :nifoc.repo) nifoc-treesitter (require :nifoc.treesitter) navic (require :nvim-navic) neogit (require :neogit)] @@ -150,6 +151,11 @@ ;; git (set mod.git {: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] (let [git-status vim.b.gitsigns_status_dict] (set self.git-head git-status.head) @@ -167,11 +173,16 @@ :callback #(neogit.open {:kind :split})} :hl {:fg colors.black :bg colors.orange :bold true}} 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}} - 5 {:provider #(.. " " $1.git-removed " ") + 6 {:provider #(.. " " $1.git-removed " ") :hl {:fg colors.bright_red}} - 6 {:provider #(.. " " $1.git-changed) :hl {:fg colors.cyan}}}) + 7 {:provider #(.. " " $1.git-changed) :hl {:fg colors.cyan}}}) ;; Diagnostics (set mod.diagnostics {:condition heirline-conditions.has_diagnostics :init (fn [self]