From 2c2824a395d05dd27c51e901e6b881446baa0522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Thu, 26 Oct 2023 09:47:21 +0200 Subject: [PATCH 1/3] feat(nvim): allow disabling cmp sources Add a new command "CmpToggle" and functions to turn off/on a cmp source. --- modules/programs/nvim/plugins/coding.nix | 3 + .../programs/nvim/plugins/lua/nvim-cmp.lua | 94 +++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/modules/programs/nvim/plugins/coding.nix b/modules/programs/nvim/plugins/coding.nix index d0c0856..955be6f 100644 --- a/modules/programs/nvim/plugins/coding.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -74,6 +74,9 @@ with builtins; } { plugin = nvim-cmp; + keys = [ + { key = "tc"; cmd = "CmpToggle"; desc = "Toggle Cmp sources"; } + ]; conf = readFile ./lua/nvim-cmp.lua; event = [ "InsertEnter" ]; dependencies = [ diff --git a/modules/programs/nvim/plugins/lua/nvim-cmp.lua b/modules/programs/nvim/plugins/lua/nvim-cmp.lua index 975d84a..516c869 100644 --- a/modules/programs/nvim/plugins/lua/nvim-cmp.lua +++ b/modules/programs/nvim/plugins/lua/nvim-cmp.lua @@ -120,3 +120,97 @@ cmp.event:on( }, }) ) + +local pickers = require("telescope.pickers") +local finders = require("telescope.finders") +local conf = require("telescope.config").values +local actions = require("telescope.actions") +local action_state = require("telescope.actions.state") + +local all_sources = vim.deepcopy(cmp.get_config().sources) + +local find = function(sources, name) + for k, source in ipairs(sources) do + if source.name == name then + return k + end + end + return nil +end + +local is_active = function(name) + local active_sources = cmp.get_config().sources + local index = find(active_sources, name) + return index ~= nil +end + +local enable_source = function(name, force) + if force or not is_active(name) then + local source_index = find(all_sources, name) + if source_index ~= nil then + local active_sources = cmp.get_config().sources + local source = all_sources[source_index] + table.insert(active_sources, 1, source) + cmp.setup({ sources = active_sources }) + end + end +end + +local disable_source = function(identifier) + if type(identifier) == "string" then + identifier = find(all_sources, identifier) + end + local active_sources = cmp.get_config().sources + table.remove(active_sources, identifier) +end + +local toggle_sources = function(name) + local active_sources = cmp.get_config().sources + local index = find(active_sources, name) + if index ~= nil then + disable_source(index) + else + enable_source(name, true) + end +end + +-- our picker function: sources +local sources_picker = function(opts) + opts = opts or {} + pickers + .new(opts, { + prompt_title = "sources", + finder = finders.new_table({ + results = vim.tbl_map(function(source) + return source.name + end, all_sources), + entry_maker = function(entry) + return { + value = entry, + display = function(tbl) + local name = tbl["ordinal"] + local active = is_active(name) + return string.format("%s %s", name, active and "✅" or "❌") + end, + ordinal = entry, + } + end, + }), + sorter = conf.generic_sorter(opts), + attach_mappings = function(prompt_bufnr, _) + actions.select_default:replace(function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + toggle_sources(selection["value"]) + end) + return true + end, + }) + :find() +end + +-- autocommand for sources_picker +vim.api.nvim_create_user_command("CmpToggle", sources_picker, {}) + +-- disable sources by default +disable_source("codeium") From 02d9e30ce77eb35117797640fda6b377a5c1a990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Fri, 27 Oct 2023 09:00:02 +0200 Subject: [PATCH 2/3] feat(tmux): add tmux-new script --- modules/programs/hyprland/_config.nix | 2 +- modules/programs/tmux/default.nix | 20 +++++++++++++++---- .../tmux/tmux-sessionizer/script.fish | 6 +----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/modules/programs/hyprland/_config.nix b/modules/programs/hyprland/_config.nix index 8c09f4b..cbeabbf 100644 --- a/modules/programs/hyprland/_config.nix +++ b/modules/programs/hyprland/_config.nix @@ -155,7 +155,7 @@ in bind = $mainMod , M , exec , hyprctl keyword general:layout master bind = $mainMod , R , exec , rofi -show combi bind = $mainMod , RETURN , exec , kitty - bind = $mainMod SHIFT , RETURN , exec , kitty -- tmux new -A -s home + bind = $mainMod SHIFT , RETURN , exec , kitty -- tmux new "ts || tn home ~" # XF86 keys binde = , XF86AudioLowerVolume , exec , pamixer -d 5 diff --git a/modules/programs/tmux/default.nix b/modules/programs/tmux/default.nix index 67a4d5f..8df5809 100644 --- a/modules/programs/tmux/default.nix +++ b/modules/programs/tmux/default.nix @@ -7,8 +7,7 @@ let tmux-switch = pkgs.writeShellApplication { name = "tmux-switch"; runtimeInputs = with pkgs; [ tmux ]; - text = '' - #!/usr/bin/env bash + text = /* bash */ '' if [[ -z ''${TMUX+x} ]]; then tmux attach -t "$1" else @@ -19,7 +18,7 @@ let tmux-sessionizer = pkgs.writeFishApplication { name = "ts"; - runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd tmux-switch gawk ]; + runtimeInputs = with pkgs; [ tmux findutils coreutils procps fd tmux-new gawk ]; text = readFile ./tmux-sessionizer/script.fish; completions = readFile ./tmux-sessionizer/completions.fish; }; @@ -31,6 +30,17 @@ let completions = readFile ./tmux-attach/completions.fish; }; + tmux-new = pkgs.writeFishApplication { + name = "tn"; + runtimeInputs = with pkgs; [ tmux ]; + text = /* fish */ '' + if ! tmux has-session -t $argv[1] 2> /dev/null + tmux new-session -ds $argv[1] -c $argv[2] + end + + tmux-switch $argv[1] + ''; + }; in { options.my.programs.tmux = { @@ -60,6 +70,8 @@ in home-manager.users.moritz.home.packages = [ tmux-sessionizer tmux-attach + tmux-switch + tmux-new ]; home-manager.users.moritz.programs = { tmux = { @@ -97,7 +109,7 @@ in if ! fish_is_root_user && test "$TERM_PROGRAM" != 'vscode' && ${insideVariableMissing} if test -z $tmux_autostarted set -x tmux_autostarted true - tmux new -A -s home + tn home ~ end end ''; diff --git a/modules/programs/tmux/tmux-sessionizer/script.fish b/modules/programs/tmux/tmux-sessionizer/script.fish index a5e957b..b9501a5 100755 --- a/modules/programs/tmux/tmux-sessionizer/script.fish +++ b/modules/programs/tmux/tmux-sessionizer/script.fish @@ -13,8 +13,4 @@ if not test -n "$selected_name" exit 1 end -if ! tmux has-session -t $selected_name 2> /dev/null - tmux new-session -ds $selected_name -c $selected -end - -tmux-switch $selected_name +tn "$selected_name" "$selected" From 70a01fd0a4850c4d4da5ad73a8a1c1358e033930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Fri, 27 Oct 2023 09:00:36 +0200 Subject: [PATCH 3/3] fix(nvim): remove lsp signature completely --- modules/programs/nvim/plugins/lua/nvim-lspconfig.lua | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/programs/nvim/plugins/lua/nvim-lspconfig.lua b/modules/programs/nvim/plugins/lua/nvim-lspconfig.lua index bfc510b..44d969d 100644 --- a/modules/programs/nvim/plugins/lua/nvim-lspconfig.lua +++ b/modules/programs/nvim/plugins/lua/nvim-lspconfig.lua @@ -106,13 +106,6 @@ local on_attach_def = function(client, bufnr) vim.lsp.inlay_hint(bufnr, true) end, timeout) end - - require("lsp_signature").on_attach({ - bind = true, -- This is mandatory, otherwise border config won't get registered. - handler_opts = { - border = "rounded", - }, - }, bufnr) end local lspconfig_default_options = {