From 1c8d22477531897dbbd7793c8e2bb60ba700d00f Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 6 Feb 2023 05:26:52 +0300 Subject: [PATCH] feat: mouse gestures & nvim-session-manager --- flake.lock | 34 +++++++++++++++ flake.nix | 21 +++++++++ modules/gestures/default.nix | 5 +++ modules/gestures/gesture-nvim.nix | 55 ++++++++++++++++++++++++ modules/lib/types-plugin.nix | 2 + modules/modules.nix | 2 + modules/session/default.nix | 5 +++ modules/session/nvim-session-manager.nix | 22 ++++++++++ 8 files changed, 146 insertions(+) create mode 100644 modules/gestures/default.nix create mode 100644 modules/gestures/gesture-nvim.nix create mode 100644 modules/session/default.nix create mode 100644 modules/session/nvim-session-manager.nix diff --git a/flake.lock b/flake.lock index 4786d1a..daae7da 100644 --- a/flake.lock +++ b/flake.lock @@ -320,6 +320,22 @@ "type": "github" } }, + "gesture-nvim": { + "flake": false, + "locked": { + "lastModified": 1675384642, + "narHash": "sha256-HxVWZopV3wx6ANefuowrdbSQpQriYHV43r187t7UJXQ=", + "owner": "notomo", + "repo": "gesture.nvim", + "rev": "902a97219e126a08aea6016994c50eea485bcd79", + "type": "github" + }, + "original": { + "owner": "notomo", + "repo": "gesture.nvim", + "type": "github" + } + }, "gitsigns-nvim": { "flake": false, "locked": { @@ -798,6 +814,22 @@ "type": "github" } }, + "nvim-session-manager": { + "flake": false, + "locked": { + "lastModified": 1675414961, + "narHash": "sha256-dHFhZtBvU6sc6XR49oL3TW0sUwAOwLf4S5q+m8u76c8=", + "owner": "Shatur", + "repo": "neovim-session-manager", + "rev": "e7a2cbf56b5fd3a223f2774b535499fc62eca6ef", + "type": "github" + }, + "original": { + "owner": "Shatur", + "repo": "neovim-session-manager", + "type": "github" + } + }, "nvim-tree-lua": { "flake": false, "locked": { @@ -983,6 +1015,7 @@ "discord-nvim": "discord-nvim", "dressing-nvim": "dressing-nvim", "flake-utils": "flake-utils", + "gesture-nvim": "gesture-nvim", "gitsigns-nvim": "gitsigns-nvim", "glow-nvim": "glow-nvim", "icon-picker-nvim": "icon-picker-nvim", @@ -1009,6 +1042,7 @@ "nvim-lspconfig": "nvim-lspconfig", "nvim-neoclip": "nvim-neoclip", "nvim-notify": "nvim-notify", + "nvim-session-manager": "nvim-session-manager", "nvim-tree-lua": "nvim-tree-lua", "nvim-treesitter-context": "nvim-treesitter-context", "nvim-ts-autotag": "nvim-ts-autotag", diff --git a/flake.nix b/flake.nix index 67e7a9b..ee27003 100644 --- a/flake.nix +++ b/flake.nix @@ -173,6 +173,14 @@ copilot.enable = false; tabnine.enable = false; # FIXME: this is not working because the plugin depends on an internal script to be ran by the package manager }; + + vim.session = { + nvim-session-manager.enable = false; + }; + + vim.gestures = { + gesture-nvim.enable = false; + }; }; }; @@ -582,6 +590,19 @@ flake = false; }; + # Session management + + nvim-session-manager = { + url = "github:Shatur/neovim-session-manager"; + flake = false; + }; + + # Mouse Gestures + gesture-nvim = { + url = "github:notomo/gesture.nvim"; + flake = false; + }; + # Dependencies plenary-nvim = { # (required by crates-nvim) diff --git a/modules/gestures/default.nix b/modules/gestures/default.nix new file mode 100644 index 0000000..4dfa40a --- /dev/null +++ b/modules/gestures/default.nix @@ -0,0 +1,5 @@ +_: { + imports = [ + ./gesture-nvim.nix + ]; +} diff --git a/modules/gestures/gesture-nvim.nix b/modules/gestures/gesture-nvim.nix new file mode 100644 index 0000000..b8aa4ce --- /dev/null +++ b/modules/gestures/gesture-nvim.nix @@ -0,0 +1,55 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; +with builtins; let + cfg = config.vim.gestures.gesture-nvim; +in { + options.vim.gestures.gesture-nvim = { + enable = mkEnableOption "Enable GitHub Copilot"; + }; + + config = mkIf cfg.enable { + vim.startPlugins = ["gesture-nvim"]; + + vim.luaConfigRC.gesture-nvim = nvim.dag.entryAnywhere '' + vim.opt.mouse = "a" + + vim.keymap.set("n", "", [[lua require("gesture").draw()]], { silent = true }) + vim.keymap.set("n", "", [[lua require("gesture").finish()]], { silent = true }) + + -- or if you would like to use right click + -- vim.keymap.set("n", "", [[]]) + -- vim.keymap.set("n", "", [[lua require("gesture").draw()]], { silent = true }) + -- vim.keymap.set("n", "", [[lua require("gesture").finish()]], { silent = true }) + + local gesture = require("gesture") + gesture.register({ + name = "scroll to bottom", + inputs = { gesture.up(), gesture.down() }, + action = "normal! G", + }) + gesture.register({ + name = "next tab", + inputs = { gesture.right() }, + action = "tabnext", + }) + gesture.register({ + name = "previous tab", + inputs = { gesture.left() }, + action = function(ctx) -- also can use callable + vim.cmd.tabprevious() + end, + }) + gesture.register({ + name = "go back", + inputs = { gesture.right(), gesture.left() }, + -- map to `` keycode + action = [[lua vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "n", true)]], + }) + ''; + }; +} diff --git a/modules/lib/types-plugin.nix b/modules/lib/types-plugin.nix index 7678951..9e31823 100644 --- a/modules/lib/types-plugin.nix +++ b/modules/lib/types-plugin.nix @@ -64,6 +64,8 @@ with lib; let "nui-nvim" "copilot-lua" "tabnine-nvim" + "nvim-session-manager" + "gesture-nvim" ]; # You can either use the name of the plugin or a package. pluginsType = with types; listOf (nullOr (either (enum availablePlugins) package)); diff --git a/modules/modules.nix b/modules/modules.nix index cde9f07..4bc7ede 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -30,6 +30,8 @@ ./terminal ./ui ./assistant + ./session + ./gestures ]; pkgsModule = {config, ...}: { diff --git a/modules/session/default.nix b/modules/session/default.nix new file mode 100644 index 0000000..3a2da67 --- /dev/null +++ b/modules/session/default.nix @@ -0,0 +1,5 @@ +_: { + imports = [ + ./nvim-session-manager.nix + ]; +} diff --git a/modules/session/nvim-session-manager.nix b/modules/session/nvim-session-manager.nix new file mode 100644 index 0000000..29dd21d --- /dev/null +++ b/modules/session/nvim-session-manager.nix @@ -0,0 +1,22 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; +with builtins; let + cfg = config.vim.session.nvim-session-manager; +in { + options.vim.session.nvim-session-manager = { + enable = mkEnableOption "Enable nvim-session-manager"; + }; + + config = mkIf cfg.enable { + vim.startPlugins = ["nvim-session-manager"]; + + vim.luaConfigRC.nvim-session-manager = nvim.dag.entryAnywhere '' + require('session_manager').setup({}) + ''; + }; +}