From 915bef780fad5dddd9d8c9bf434b10f6eaffa108 Mon Sep 17 00:00:00 2001 From: justchokingaround Date: Wed, 22 May 2024 05:07:17 +0200 Subject: [PATCH] new: add cokeline --- flake.lock | 17 ++++ flake.nix | 6 ++ modules/plugins/tabline/cokeline/cokeline.nix | 17 ++++ modules/plugins/tabline/cokeline/config.nix | 95 +++++++++++++++++++ modules/plugins/tabline/cokeline/default.nix | 6 ++ modules/plugins/tabline/default.nix | 1 + .../tabline/nvim-bufferline/config.nix | 1 - 7 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 modules/plugins/tabline/cokeline/cokeline.nix create mode 100644 modules/plugins/tabline/cokeline/config.nix create mode 100644 modules/plugins/tabline/cokeline/default.nix diff --git a/flake.lock b/flake.lock index eeb136e..1569668 100644 --- a/flake.lock +++ b/flake.lock @@ -1021,6 +1021,22 @@ "type": "github" } }, + "plugin-nvim-cokeline": { + "flake": false, + "locked": { + "lastModified": 1715991329, + "narHash": "sha256-FXXh+a5hld9e1nW53S7vgumW4AD3bbMuewxmZyN+WvI=", + "owner": "willothy", + "repo": "nvim-cokeline", + "rev": "8145048ae68e05f31979c13b0adf7aa99f04f4c0", + "type": "github" + }, + "original": { + "owner": "willothy", + "repo": "nvim-cokeline", + "type": "github" + } + }, "plugin-nvim-colorizer-lua": { "flake": false, "locked": { @@ -1804,6 +1820,7 @@ "plugin-nvim-bufferline-lua": "plugin-nvim-bufferline-lua", "plugin-nvim-cmp": "plugin-nvim-cmp", "plugin-nvim-code-action-menu": "plugin-nvim-code-action-menu", + "plugin-nvim-cokeline": "plugin-nvim-cokeline", "plugin-nvim-colorizer-lua": "plugin-nvim-colorizer-lua", "plugin-nvim-cursorline": "plugin-nvim-cursorline", "plugin-nvim-dap": "plugin-nvim-dap", diff --git a/flake.nix b/flake.nix index 88f5615..4afc77d 100644 --- a/flake.nix +++ b/flake.nix @@ -223,6 +223,12 @@ flake = false; }; + # Cokeline + plugin-nvim-cokeline = { + url = "github:willothy/nvim-cokeline"; + flake = false; + }; + # Statuslines plugin-lualine = { url = "github:hoob3rt/lualine.nvim"; diff --git a/modules/plugins/tabline/cokeline/cokeline.nix b/modules/plugins/tabline/cokeline/cokeline.nix new file mode 100644 index 0000000..bbacbbd --- /dev/null +++ b/modules/plugins/tabline/cokeline/cokeline.nix @@ -0,0 +1,17 @@ +{lib, ...}: let + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; +in { + options.vim.tabline.cokeline = { + enable = mkEnableOption "cokeline"; + + mappings = { + cycleNext = mkMappingOption "Next buffer" ""; + cyclePrevious = mkMappingOption "Previous buffer" ""; + pick = mkMappingOption "Pick buffer" "bc"; + switchNext = mkMappingOption "Switch with next buffer" "bmn"; + switchPrevious = mkMappingOption "Move previous buffer" "bmp"; + closeByLetter = mkMappingOption "Close buffer by letter" "bd"; + }; + }; +} diff --git a/modules/plugins/tabline/cokeline/config.nix b/modules/plugins/tabline/cokeline/config.nix new file mode 100644 index 0000000..97bac52 --- /dev/null +++ b/modules/plugins/tabline/cokeline/config.nix @@ -0,0 +1,95 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.binds) mkBinding pushDownDefault; + inherit (lib.nvim.dag) entryAnywhere; + + cfg = config.vim.tabline.cokeline; + + self = import ./cokeline.nix {inherit lib;}; + inherit (self.options.vim.tabline.cokeline) mappings; +in { + config = mkIf cfg.enable { + vim = { + startPlugins = [ + (assert config.vim.visuals.nvimWebDevicons.enable; "nvim-cokeline") + "bufdelete-nvim" + ]; + + maps.normal = mkMerge [ + (mkBinding cfg.mappings.cycleNext "(cokeline-focus-next)" mappings.cycleNext.description) + (mkBinding cfg.mappings.cyclePrevious "(cokeline-focus-prev)" mappings.cyclePrevious.description) + (mkBinding cfg.mappings.switchNext "(cokeline-switch-next)" mappings.switchNext.description) + (mkBinding cfg.mappings.switchPrevious "(cokeline-switch-prev)" mappings.switchPrevious.description) + # this does not work + # (mkBinding cfg.mappings.pick "(cokeline-pick-focus)" mappings.pick.description) + # (mkLuaBinding cfg.mappings.pick "function() require('cokeline.mappings').pick(\"focus\") end" mappings.pick.description) + # (mkBinding cfg.mappings.closeByLetter "(cokeline-pick-close)" mappings.closeByLetter.description) + ]; + + binds.whichKey.register = pushDownDefault { + "b" = "+Buffer"; + "bm" = "BufferLineMove"; + }; + + luaConfigRC = { + cokeline = entryAnywhere '' + local get_hex = require('cokeline.hlgroups').get_hl_attr + + require('cokeline').setup({ + default_hl = { + fg = function(buffer) + return + buffer.is_focused + and get_hex('Normal', 'fg') + or get_hex('Comment', 'fg') + end, + bg = get_hex('ColorColumn', 'bg'), + }, + + components = { + { + text = ' ', + bg = get_hex('Normal', 'bg'), + }, + { + text = '', + fg = get_hex('ColorColumn', 'bg'), + bg = get_hex('Normal', 'bg'), + }, + { + text = function(buffer) + return buffer.devicon.icon + end, + fg = function(buffer) + return buffer.devicon.color + end, + }, + { + text = ' ', + }, + { + text = function(buffer) return buffer.filename .. ' ' end, + style = function(buffer) + return buffer.is_focused and 'bold' or nil + end, + }, + { + text = '', + delete_buffer_on_left_click = true, + }, + { + text = '', + fg = get_hex('ColorColumn', 'bg'), + bg = get_hex('Normal', 'bg'), + }, + }, + }) + ''; + }; + }; + }; +} diff --git a/modules/plugins/tabline/cokeline/default.nix b/modules/plugins/tabline/cokeline/default.nix new file mode 100644 index 0000000..ab19972 --- /dev/null +++ b/modules/plugins/tabline/cokeline/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./cokeline.nix + ./config.nix + ]; +} diff --git a/modules/plugins/tabline/default.nix b/modules/plugins/tabline/default.nix index 5730dba..6290096 100644 --- a/modules/plugins/tabline/default.nix +++ b/modules/plugins/tabline/default.nix @@ -1,5 +1,6 @@ { imports = [ ./nvim-bufferline + ./cokeline ]; } diff --git a/modules/plugins/tabline/nvim-bufferline/config.nix b/modules/plugins/tabline/nvim-bufferline/config.nix index 93b0f58..4206130 100644 --- a/modules/plugins/tabline/nvim-bufferline/config.nix +++ b/modules/plugins/tabline/nvim-bufferline/config.nix @@ -32,7 +32,6 @@ in { maps.normal = mkMerge [ (mkLuaBinding cfg.mappings.closeCurrent "require(\"bufdelete\").bufdelete" mappings.closeCurrent.description) (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext" mappings.cycleNext.description) - (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext" mappings.cycleNext.description) (mkBinding cfg.mappings.cyclePrevious ":BufferLineCyclePrev" mappings.cyclePrevious.description) (mkBinding cfg.mappings.pick ":BufferLinePick" mappings.pick.description) (mkBinding cfg.mappings.sortByExtension ":BufferLineSortByExtension" mappings.sortByExtension.description)