From b471d0fa7a7d49e3fb3010ff771a97f1b4f0108f Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sun, 5 Nov 2023 20:40:18 -0500 Subject: [PATCH] create more optional neovim settings --- hosts/aws/main.tf | 2 +- modules/common/neovim/config/github.lua | 14 ++++++++++++++ modules/common/neovim/config/kubernetes.lua | 6 ++++++ modules/common/neovim/config/lsp.nix | 13 ++++++++++--- modules/common/neovim/config/toggleterm.lua | 12 ------------ modules/common/neovim/config/toggleterm.nix | 8 ++++++-- modules/common/neovim/default.nix | 4 +++- modules/common/neovim/lua/keybinds.lua | 1 - modules/common/neovim/package/default.nix | 4 ++-- 9 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 modules/common/neovim/config/github.lua create mode 100644 modules/common/neovim/config/kubernetes.lua diff --git a/hosts/aws/main.tf b/hosts/aws/main.tf index 4fbb2ca..b9abd5c 100644 --- a/hosts/aws/main.tf +++ b/hosts/aws/main.tf @@ -26,7 +26,7 @@ data "aws_iam_policy_document" "vmimport" { actions = [ "s3:GetBucketLocation", "s3:GetObject", - "s3:ListBucket", + "s3:ListBucket", ] resources = [ "arn:aws:s3:::${aws_s3_object.image.bucket}", diff --git a/modules/common/neovim/config/github.lua b/modules/common/neovim/config/github.lua new file mode 100644 index 0000000..0a8f139 --- /dev/null +++ b/modules/common/neovim/config/github.lua @@ -0,0 +1,14 @@ +-- Keymap to open file in GitHub web +vim.keymap.set("n", "gr", ":!gh browse %", { silent = true }) + +-- Pop a terminal to watch the current run +local gitwatch = + require("toggleterm.terminal").Terminal:new({ cmd = "fish --interactive --init-command 'gh run watch'" }) + +-- Set a toggle for this terminal +function GITWATCH_TOGGLE() + gitwatch:toggle() +end + +-- Keymap to toggle the run +vim.keymap.set("n", "gw", GITWATCH_TOGGLE) diff --git a/modules/common/neovim/config/kubernetes.lua b/modules/common/neovim/config/kubernetes.lua new file mode 100644 index 0000000..67819ae --- /dev/null +++ b/modules/common/neovim/config/kubernetes.lua @@ -0,0 +1,6 @@ +local k9s = require("toggleterm.terminal").Terminal:new({ cmd = "k9s" }) +function K9S_TOGGLE() + k9s:toggle() +end + +vim.keymap.set("n", "9", K9S_TOGGLE) diff --git a/modules/common/neovim/config/lsp.nix b/modules/common/neovim/config/lsp.nix index e173285..848d1a6 100644 --- a/modules/common/neovim/config/lsp.nix +++ b/modules/common/neovim/config/lsp.nix @@ -1,13 +1,16 @@ { pkgs, lib, config, dsl, ... }: { # Terraform optional because non-free - options.useTerraform = lib.mkEnableOption "Whether to enable Terraform LSP"; + options.terraform = lib.mkEnableOption "Whether to enable Terraform LSP"; + options.github = lib.mkEnableOption "Whether to enable GitHub features"; + options.kubernetes = + lib.mkEnableOption "Whether to enable Kubernetes features"; config = let - terraformFormat = if config.useTerraform then '' + terraformFormat = if config.terraform then '' require("null-ls").builtins.formatting.terraform_fmt.with({ command = "${pkgs.terraform}/bin/terraform", extra_filetypes = { "hcl" }, @@ -40,7 +43,11 @@ }; use.lspconfig.terraformls.setup = dsl.callWith { - cmd = [ "${pkgs.terraform-ls}/bin/terraform-ls" "serve" ]; + cmd = if config.terraform then [ + "${pkgs.terraform-ls}/bin/terraform-ls" + "serve" + ] else + [ "echo" ]; }; use.lspconfig.rust_analyzer.setup = dsl.callWith { diff --git a/modules/common/neovim/config/toggleterm.lua b/modules/common/neovim/config/toggleterm.lua index 2e9c6cb..bd011bc 100644 --- a/modules/common/neovim/config/toggleterm.lua +++ b/modules/common/neovim/config/toggleterm.lua @@ -26,17 +26,5 @@ function NIXPKGS_TOGGLE() nixpkgs:toggle() end -local gitwatch = terminal:new({ cmd = "fish --interactive --init-command 'gh run watch'" }) -function GITWATCH_TOGGLE() - gitwatch:toggle() -end - -local k9s = terminal:new({ cmd = "k9s" }) -function K9S_TOGGLE() - k9s:toggle() -end - vim.keymap.set("n", "t", TERM_TOGGLE) vim.keymap.set("n", "P", NIXPKGS_TOGGLE) -vim.keymap.set("n", "gw", GITWATCH_TOGGLE) -vim.keymap.set("n", "9", K9S_TOGGLE) diff --git a/modules/common/neovim/config/toggleterm.nix b/modules/common/neovim/config/toggleterm.nix index 8dac46f..42fbe73 100644 --- a/modules/common/neovim/config/toggleterm.nix +++ b/modules/common/neovim/config/toggleterm.nix @@ -1,4 +1,4 @@ -{ pkgs, dsl, ... }: { +{ pkgs, dsl, config, ... }: { # Toggleterm provides a floating terminal inside the editor for quick access @@ -10,6 +10,10 @@ direction = "float"; }; - lua = builtins.readFile ./toggleterm.lua; + lua = '' + ${builtins.readFile ./toggleterm.lua} + ${if config.github then (builtins.readFile ./github.lua) else ""} + ${if config.kubernetes then (builtins.readFile ./kubernetes.lua) else ""} + ''; } diff --git a/modules/common/neovim/default.nix b/modules/common/neovim/default.nix index 0dfa703..d841874 100644 --- a/modules/common/neovim/default.nix +++ b/modules/common/neovim/default.nix @@ -5,7 +5,9 @@ let neovim = import ./package { inherit pkgs; colors = config.theme.colors; - useTerraform = config.terraform.enable; + terraform = config.terraform.enable; + github = true; + kubernetes = config.kubernetes.enable; }; in { diff --git a/modules/common/neovim/lua/keybinds.lua b/modules/common/neovim/lua/keybinds.lua index f92df91..0e502d7 100644 --- a/modules/common/neovim/lua/keybinds.lua +++ b/modules/common/neovim/lua/keybinds.lua @@ -39,7 +39,6 @@ key("n", "fs", ":write") key("n", "fd", ":lcd %:p:h", { silent = true }) key("n", "fu", ":lcd ..", { silent = true }) key("n", "", ":b#", { silent = true }) -key("n", "gr", ":!gh browse %", { silent = true }) key("n", "tt", [[exe 'edit $NOTES_PATH/journal/'.strftime("%Y-%m-%d_%a").'.md']]) key("n", "jj", ":!journal:e") diff --git a/modules/common/neovim/package/default.nix b/modules/common/neovim/package/default.nix index 2fc5864..806df38 100644 --- a/modules/common/neovim/package/default.nix +++ b/modules/common/neovim/package/default.nix @@ -26,13 +26,13 @@ # ] ++ extraConfig; # } -{ pkgs, colors, useTerraform ? false, ... }: +{ pkgs, colors, terraform ? false, github ? false, kubernetes ? false, ... }: # Comes from nix2vim overlay: # https://github.com/gytis-ivaskevicius/nix2vim/blob/master/lib/neovim-builder.nix pkgs.neovimBuilder { package = pkgs.neovim-unwrapped; - inherit colors useTerraform; + inherit colors terraform github kubernetes; imports = [ ../config/align.nix ../config/bufferline.nix