From ffdb9eb0e55aaf506cff2abf2be013bdb46a1ce5 Mon Sep 17 00:00:00 2001 From: Tawfeeq Date: Sun, 6 Apr 2025 14:09:10 +0200 Subject: [PATCH] updated bufferline --- init.lua | 1 + lua/custom/config/lualine_config.lua | 108 +++++++----------- lua/custom/plugins/alpha-nvim.lua | 31 +++++ lua/custom/plugins/bufferline.lua | 44 ++++++- lua/custom/plugins/telescope-file-browser.lua | 17 +++ 5 files changed, 129 insertions(+), 72 deletions(-) create mode 100644 lua/custom/plugins/telescope-file-browser.lua diff --git a/init.lua b/init.lua index 2989c899..bfad7489 100644 --- a/init.lua +++ b/init.lua @@ -346,6 +346,7 @@ vim.opt.rtp:prepend(lazypath) -- To update plugins you can run -- :Lazy update -- +vim.o.mouse = 'a' -- NOTE: Here is where you install your plugins. require('lazy').setup({ -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link). diff --git a/lua/custom/config/lualine_config.lua b/lua/custom/config/lualine_config.lua index 041aab35..938a911f 100644 --- a/lua/custom/config/lualine_config.lua +++ b/lua/custom/config/lualine_config.lua @@ -1,5 +1,3 @@ --- ~/.config/nvim/lua/custom/config/lualine_config.lua - local lualine = require 'lualine' -- Color table for highlights @@ -35,68 +33,49 @@ local conditions = { -- Config local config = { options = { - -- Disable sections and component separators component_separators = '', section_separators = '', - -- theme = { - -- -- We are going to use lualine_c and lualine_x as left and - -- -- right sections. Both are highlighted by the c theme. - -- -- So we are just setting default looks of statusline - -- normal = { c = { fg = colors.fg, bg = colors.bg } }, - -- inactive = { c = { fg = colors.fg, bg = colors.bg } }, - -- }, + theme = { + normal = { c = { fg = colors.fg, bg = colors.bg } }, + inactive = { c = { fg = colors.fg, bg = colors.bg } }, + }, }, sections = { - -- these are to remove the defaults - lualine_a = { - -- { - -- 'buffers', - -- show_filename_only = false, - -- }, - }, - lualine_b = {}, - lualine_y = {}, - lualine_z = {}, - -- These will be filled later - lualine_c = {}, - lualine_x = {}, - }, - inactive_sections = { - -- these are to remove the defaults lualine_a = {}, lualine_b = {}, - lualine_y = {}, - lualine_z = {}, lualine_c = {}, lualine_x = {}, + lualine_y = {}, + lualine_z = {}, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {}, }, } --- Inserts a component in lualine_c at the left section local function ins_left(component) table.insert(config.sections.lualine_c, component) end --- Inserts a component in lualine_x at the right section local function ins_right(component) table.insert(config.sections.lualine_x, component) end +-- Left components ins_left { - function() - return '▊' - end, - color = { fg = colors.blue }, -- Sets highlighting of component - padding = { left = 0, right = 1 }, -- No space before this + function() return '▊' end, + color = { fg = colors.blue }, + padding = { left = 0, right = 1 }, } ins_left { - -- mode component - function() - return '' - end, + function() return '' end, color = function() - -- Auto change color according to Neovim's mode local mode_color = { n = colors.red, i = colors.green, @@ -124,21 +103,25 @@ ins_left { padding = { right = 1 }, } -ins_left { - -- filesize component - 'filesize', - cond = conditions.buffer_not_empty, -} - +-- THIS IS THE MODIFIED COMPONENT (shows path) ins_left { 'filename', cond = conditions.buffer_not_empty, color = { fg = colors.magenta, gui = 'bold' }, + path = 1, -- Show relative path (2-3 parent directories) } -ins_left { 'location', show_filename_only = false } +ins_left { + function() + local buf_count = #vim.fn.getbufinfo({buflisted = 1}) + return 'Buffers: ' .. buf_count + end, + color = { fg = colors.cyan }, +} + +ins_left { 'location' } ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } } -ins_left { 'buffers', show_filename_only = false } + ins_left { 'diagnostics', sources = { 'nvim_diagnostic' }, @@ -150,23 +133,14 @@ ins_left { }, } --- Insert mid section. You can make any number of sections in Neovim :) --- for lualine it's any number greater than 2 -ins_left { - function() - return '%=' - end, -} +ins_left { function() return '%=' end } ins_left { - -- Lsp server name function() local msg = 'No Active Lsp' local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype') local clients = vim.lsp.get_active_clients() - if next(clients) == nil then - return msg - end + if next(clients) == nil then return msg end for _, client in ipairs(clients) do local filetypes = client.config.filetypes if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then @@ -179,10 +153,10 @@ ins_left { color = { fg = '#ffffff', gui = 'bold' }, } --- Add components to right sections +-- Right components ins_right { - 'o:encoding', -- option component same as &encoding in viml - fmt = string.upper, -- Convert to uppercase + 'o:encoding', + fmt = string.upper, cond = conditions.hide_in_width, color = { fg = colors.green, gui = 'bold' }, } @@ -190,19 +164,18 @@ ins_right { ins_right { 'fileformat', fmt = string.upper, - icons_enabled = false, -- Disable icons + icons_enabled = false, color = { fg = colors.green, gui = 'bold' }, } ins_right { 'branch', icon = '', - color = { fg = colors.red, gui = 'bold' }, + color = { fg = colors.violet, gui = 'bold' }, } ins_right { 'diff', - -- Symbols for diff symbols = { added = ' ', modified = '󰝤 ', removed = ' ' }, diff_color = { added = { fg = colors.green }, @@ -213,12 +186,9 @@ ins_right { } ins_right { - function() - return '▊' - end, + function() return '▊' end, color = { fg = colors.blue }, padding = { left = 1 }, } --- Initialize lualine with the configuration lualine.setup(config) diff --git a/lua/custom/plugins/alpha-nvim.lua b/lua/custom/plugins/alpha-nvim.lua index 81eed88f..0d87a0f8 100644 --- a/lua/custom/plugins/alpha-nvim.lua +++ b/lua/custom/plugins/alpha-nvim.lua @@ -1,10 +1,14 @@ return { 'goolord/alpha-nvim', + priority = 1000, dependencies = { 'nvim-tree/nvim-web-devicons', + 'echasnovski/mini.icons', + 'nvim-lua/plenary.nvim', }, config = function() + require('alpha').setup(require('alpha.themes.theta').config) local alpha = require 'alpha' local dashboard = require 'alpha.themes.startify' @@ -25,7 +29,34 @@ return { [[ ]], [[ ]], } + -- dashboard.section.header.val = { + -- [[ ]], + -- [[ ]], + -- [[ ]], + -- [[ ]], + -- [[ .-') _ ('-. (`-. _ .-') ]], + -- [[ ( OO ) )_( OO) _(OO )_ ( '.( OO )_ ]], + -- [[,--./ ,--,'(,------. .-'),-----. ,--(_/ ,. \ ,-.-') ,--. ,--.)]], + -- [[| \ | |\ | .---'( OO' .-. '\ \ /(__/ | |OO)| `.' | ]], + -- [[| \| | )| | / | | | | \ \ / / | | \| | ]], + -- [[| . |/(| '--. \_) | |\| | \ ' /, | |(_/| |'.'| | ]], + -- [[| |\ | | .--' \ | | | | \ /__),| |_.'| | | | ]], + -- [[| | \ | | `---. `' '-' ' \ / (_| | | | | | ]], + -- [[`--' `--' `------' `-----' `-' `--' `--' `--' ]], + -- [[ ]], + -- [[ ]], + -- [[ ]], + -- } + -- dashboard.section.header.val = { + -- + -- [[ _ _ _ ]], + -- [[ | \| | ___ ___ __ __ (_) _ __ ]], + -- [[ | .` | / -_) / _ \ \ V / | | | ' \ ]], + -- [[ |_|\_| \___| \___/ _\_/_ _|_|_ |_|_|_| ]], + -- [[ _|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| ]], + -- [[ "`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' ]], + -- } alpha.setup(dashboard.opts) end, } diff --git a/lua/custom/plugins/bufferline.lua b/lua/custom/plugins/bufferline.lua index f94638e3..d909b01e 100644 --- a/lua/custom/plugins/bufferline.lua +++ b/lua/custom/plugins/bufferline.lua @@ -1,8 +1,46 @@ return { 'akinsho/bufferline.nvim', - version = "*", + version = '*', dependencies = 'nvim-tree/nvim-web-devicons', config = function() - require("bufferline").setup{} - end + require('bufferline').setup { + options = { + diagnostics = 'nvim_lsp', + diagnostics_indicator = function(count, level) + local icon = level:match 'error' and ' ' or ' ' + return ' ' .. icon .. count + end, + hover = { + enabled = true, + delay = 200, + reveal = { 'close' }, + }, + offsets = { + { + filetype = 'NvimTree', + text = function() + return vim.fn.getcwd() + end, + highlight = 'Directory', + text_align = 'left', + }, + }, + }, + } + vim.keymap.set('n', 'bk', ':BufferLinePick', { silent = true }) + vim.keymap.set('n', 'bkk', ':BufferLinePickClose', { silent = true }) + vim.keymap.set('n', 'bl', ':BufferLineCloseLeft', { silent = true }) + vim.keymap.set('n', 'br', ':BufferLineCloseRight', { silent = true }) + -- Remaps + vim.keymap.set('n', '1', ':BufferLineGoToBuffer 1', { silent = true }) + vim.keymap.set('n', '2', ':BufferLineGoToBuffer 2', { silent = true }) + vim.keymap.set('n', '3', ':BufferLineGoToBuffer 3', { silent = true }) + vim.keymap.set('n', '4', ':BufferLineGoToBuffer 4', { silent = true }) + vim.keymap.set('n', '5', ':BufferLineGoToBuffer 5', { silent = true }) + vim.keymap.set('n', '6', ':BufferLineGoToBuffer 6', { silent = true }) + vim.keymap.set('n', '7', ':BufferLineGoToBuffer 7', { silent = true }) + vim.keymap.set('n', '8', ':BufferLineGoToBuffer 8', { silent = true }) + vim.keymap.set('n', '9', ':BufferLineGoToBuffer 9', { silent = true }) + vim.keymap.set('n', '$', ':BufferLineGoToBuffer -1', { silent = true }) + end, } diff --git a/lua/custom/plugins/telescope-file-browser.lua b/lua/custom/plugins/telescope-file-browser.lua new file mode 100644 index 00000000..3bda73e6 --- /dev/null +++ b/lua/custom/plugins/telescope-file-browser.lua @@ -0,0 +1,17 @@ +return { + 'nvim-telescope/telescope-file-browser.nvim', + dependencies = { 'nvim-telescope/telescope.nvim', 'nvim-lua/plenary.nvim' }, + +vim.keymap.set("n", "fb", ":Telescope file_browser"), + +-- open file_browser with the path of the current buffer +vim.keymap.set("n", "fb", ":Telescope file_browser path=%:p:h select_buffer=true"), + +-- Alternatively, using lua API +vim.keymap.set("n", "fb", function() + require("telescope").extensions.file_browser.file_browser() +end) +} + + +