From ac3aaf3f7b533a556e8037f45f1be8f7a7434f25 Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Wed, 1 May 2024 13:21:41 +0200 Subject: [PATCH] nvim: detect remote repo type based on url --- home/config/nvim/nifoc/repo.fnl | 17 ++++++++++++----- home/config/nvim/nifoc/statusline.fnl | 6 ++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/home/config/nvim/nifoc/repo.fnl b/home/config/nvim/nifoc/repo.fnl index 3127618..710021b 100644 --- a/home/config/nvim/nifoc/repo.fnl +++ b/home/config/nvim/nifoc/repo.fnl @@ -1,5 +1,12 @@ (let [mod {} - wezterm (require :wezterm)] + wezterm (require :wezterm) + remote-origin (vim.fn.system "git remote get-url origin")] + (match remote-origin + (where r (r:find :git.kempkens.io)) (set mod.type :forgejo) + (where r (r:find :git.app.nedeco.de)) (set mod.type :gitlab) + (where r (r:find :github.com)) (set mod.type :github) + _ (set mod.type (or vim.env.REMOTE_REPO_TYPE :default))) + (fn exe [bin] (vim.fn.exepath bin)) (fn run-cmd [program] @@ -23,25 +30,25 @@ vim.log.levels.ERROR [])))))) (fn mod.open-repo [] - (case vim.env.REMOTE_REPO_TYPE + (case mod.type :github nil :gitlab (run-cmd [:glab :repo :view :--web]) :forgejo (run-cmd [:tea :open]))) (fn mod.open-merge-request [] - (case vim.env.REMOTE_REPO_TYPE + (case mod.type :github nil :gitlab (run-cmd [:glab :mr :view :--web]) :forgejo nil)) (fn mod.open-ci [] - (case vim.env.REMOTE_REPO_TYPE + (case mod.type :github nil :gitlab (open-split [(exe :glab) :pipeline :ci :view]) :forgejo nil)) (fn mod.run-ci [] - (case vim.env.REMOTE_REPO_TYPE + (case mod.type :github nil :gitlab (do (run-cmd [:glab :pipeline :run]) diff --git a/home/config/nvim/nifoc/statusline.fnl b/home/config/nvim/nifoc/statusline.fnl index d9d798a..c270fb4 100644 --- a/home/config/nvim/nifoc/statusline.fnl +++ b/home/config/nvim/nifoc/statusline.fnl @@ -151,15 +151,13 @@ ;; git (set mod.git {:condition heirline-conditions.is_git_repo - :static {:git-repo-type (or vim.env.REMOTE_REPO_TYPE :default) - :git-repo-icons {:github "" + :static {:git-repo-icons {:github "" :gitlab "" :forgejo "" :default ""}} :init (fn [self] (let [git-status vim.b.gitsigns_status_dict] - (set self.git-repo-icon - (. self.git-repo-icons self.git-repo-type)) + (set self.git-repo-icon (. self :git-repo-icons repo.type)) (set self.git-head git-status.head) (set self.git-added (or git-status.added 0)) (set self.git-removed (or git-status.removed 0))