create more optional neovim settings

This commit is contained in:
Noah Masur 2023-11-05 20:40:18 -05:00
parent cf7d1b50f8
commit b471d0fa7a
9 changed files with 42 additions and 22 deletions

View File

@ -0,0 +1,14 @@
-- Keymap to open file in GitHub web
vim.keymap.set("n", "<Leader>gr", ":!gh browse %<CR><CR>", { 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", "<Leader>gw", GITWATCH_TOGGLE)

View File

@ -0,0 +1,6 @@
local k9s = require("toggleterm.terminal").Terminal:new({ cmd = "k9s" })
function K9S_TOGGLE()
k9s:toggle()
end
vim.keymap.set("n", "<Leader>9", K9S_TOGGLE)

View File

@ -1,13 +1,16 @@
{ pkgs, lib, config, dsl, ... }: { { pkgs, lib, config, dsl, ... }: {
# Terraform optional because non-free # 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 = config =
let let
terraformFormat = if config.useTerraform then '' terraformFormat = if config.terraform then ''
require("null-ls").builtins.formatting.terraform_fmt.with({ require("null-ls").builtins.formatting.terraform_fmt.with({
command = "${pkgs.terraform}/bin/terraform", command = "${pkgs.terraform}/bin/terraform",
extra_filetypes = { "hcl" }, extra_filetypes = { "hcl" },
@ -40,7 +43,11 @@
}; };
use.lspconfig.terraformls.setup = dsl.callWith { 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 { use.lspconfig.rust_analyzer.setup = dsl.callWith {

View File

@ -26,17 +26,5 @@ function NIXPKGS_TOGGLE()
nixpkgs:toggle() nixpkgs:toggle()
end 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", "<Leader>t", TERM_TOGGLE) vim.keymap.set("n", "<Leader>t", TERM_TOGGLE)
vim.keymap.set("n", "<Leader>P", NIXPKGS_TOGGLE) vim.keymap.set("n", "<Leader>P", NIXPKGS_TOGGLE)
vim.keymap.set("n", "<Leader>gw", GITWATCH_TOGGLE)
vim.keymap.set("n", "<Leader>9", K9S_TOGGLE)

View File

@ -1,4 +1,4 @@
{ pkgs, dsl, ... }: { { pkgs, dsl, config, ... }: {
# Toggleterm provides a floating terminal inside the editor for quick access # Toggleterm provides a floating terminal inside the editor for quick access
@ -10,6 +10,10 @@
direction = "float"; 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 ""}
'';
} }

View File

@ -5,7 +5,9 @@ let
neovim = import ./package { neovim = import ./package {
inherit pkgs; inherit pkgs;
colors = config.theme.colors; colors = config.theme.colors;
useTerraform = config.terraform.enable; terraform = config.terraform.enable;
github = true;
kubernetes = config.kubernetes.enable;
}; };
in { in {

View File

@ -39,7 +39,6 @@ key("n", "<Leader>fs", ":write<CR>")
key("n", "<Leader>fd", ":lcd %:p:h<CR>", { silent = true }) key("n", "<Leader>fd", ":lcd %:p:h<CR>", { silent = true })
key("n", "<Leader>fu", ":lcd ..<CR>", { silent = true }) key("n", "<Leader>fu", ":lcd ..<CR>", { silent = true })
key("n", "<Leader><Tab>", ":b#<CR>", { silent = true }) key("n", "<Leader><Tab>", ":b#<CR>", { silent = true })
key("n", "<Leader>gr", ":!gh browse %<CR><CR>", { silent = true })
key("n", "<Leader>tt", [[<Cmd>exe 'edit $NOTES_PATH/journal/'.strftime("%Y-%m-%d_%a").'.md'<CR>]]) key("n", "<Leader>tt", [[<Cmd>exe 'edit $NOTES_PATH/journal/'.strftime("%Y-%m-%d_%a").'.md'<CR>]])
key("n", "<Leader>jj", ":!journal<CR>:e<CR>") key("n", "<Leader>jj", ":!journal<CR>:e<CR>")

View File

@ -26,13 +26,13 @@
# ] ++ extraConfig; # ] ++ extraConfig;
# } # }
{ pkgs, colors, useTerraform ? false, ... }: { pkgs, colors, terraform ? false, github ? false, kubernetes ? false, ... }:
# Comes from nix2vim overlay: # Comes from nix2vim overlay:
# https://github.com/gytis-ivaskevicius/nix2vim/blob/master/lib/neovim-builder.nix # https://github.com/gytis-ivaskevicius/nix2vim/blob/master/lib/neovim-builder.nix
pkgs.neovimBuilder { pkgs.neovimBuilder {
package = pkgs.neovim-unwrapped; package = pkgs.neovim-unwrapped;
inherit colors useTerraform; inherit colors terraform github kubernetes;
imports = [ imports = [
../config/align.nix ../config/align.nix
../config/bufferline.nix ../config/bufferline.nix