refractor(nvim): Refractor lualine.nvim

This commit is contained in:
js0ny 2025-01-26 20:47:38 +00:00
parent a5218cdea7
commit 21a77b4524
11 changed files with 231 additions and 208 deletions

View file

@ -8,6 +8,6 @@
# ln -sf $DOTFILES/tools/fish ~/.config/fish
if command -v starship > /dev/null
set -gx STARSHIP_CONFIG "~/.dotfiles/tools/starship/starship_fish.toml"
#set -gx STARSHIP_CONFIG "~/.dotfiles/tools/starship/starship_fish.toml"
starship init fish | source
end

View file

@ -36,7 +36,6 @@
"nvim-web-devicons": { "branch": "master", "commit": "37334adf4517fecfd97c0b44e1d4718e377e9e52" },
"obsidian.nvim": { "branch": "main", "commit": "ae1f76a75c7ce36866e1d9342a8f6f5b9c2caf9b" },
"onedarkpro.nvim": { "branch": "main", "commit": "44775f8206ee43b692e7f3dc894ddc47996ee523" },
"orgmode": { "branch": "master", "commit": "13b5ff707b42d4c561009bfe7fe4ccf31e8910a1" },
"plenary.nvim": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" },
"project.nvim": { "branch": "main", "commit": "8c6bad7d22eef1b71144b401c9f74ed01526a4fb" },
"render-markdown.nvim": { "branch": "main", "commit": "ad055861d17afe058bd835e82292e14a64b51b1d" },
@ -48,7 +47,7 @@
"vim-just": { "branch": "main", "commit": "d07978c23c967c54c04a4dff9b25bcd6de5e91e0" },
"vim-visual-multi-colemak-hnei": { "branch": "master", "commit": "2cc37d77590d6569d991ebd8d96ab5867eb5a47a" },
"vim-wakatime": { "branch": "master", "commit": "e46d7c4f98ee0f40782008dd60cb2a79c377fb1d" },
"vimtex": { "branch": "master", "commit": "b4eb43603dccf33b7d8597fbe1403c6430a24886" },
"vimtex": { "branch": "master", "commit": "83e331dcad5ce28012e656eea3906b5b897db2ba" },
"which-key.nvim": { "branch": "main", "commit": "6cebd86917df559a88de0f806b2989799c6e6423" },
"winbar.nvim": { "branch": "main", "commit": "13739fdb31be51a1000486189662596f07a59a31" },
"yanky.nvim": { "branch": "main", "commit": "d2696b30e389dced94d5acab728f524a25f308d2" }

View file

@ -0,0 +1,16 @@
local colors = {
bg = "#202328",
fg = "#bbc2cf",
yellow = "#ECBE7B",
cyan = "#008080",
darkblue = "#081633",
green = "#98be65",
orange = "#FF8800",
violet = "#a9a1e1",
magenta = "#c678dd",
purple = "#c678dd",
blue = "#51afef",
red = "#ec5f67",
}
return colors

View file

@ -1,9 +1,4 @@
local signs = {
Error = "",
Warning = "",
Hint = "",
Information = "",
}
local signs = require("config.icons").diagnostics
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type

View file

@ -0,0 +1,19 @@
local M = {
diagnostics = {
Error = "",
Warning = "",
Hint = "",
Information = "",
},
lsp = "",
indent = "",
git = {
Change = "",
Add = "",
Delete = "",
Rename = "",
Branch = "",
},
}
return M

View file

@ -2,7 +2,7 @@ local M = {}
M.global = {
{ mode = "n", keys = "<leader>E", cmd = ":NvimTreeToggle<CR>" },
{ mode = "n", keys = "<A-0>", cmd = ":NvimTreeFocus<CR>" },
{ mode = "n", keys = "<A-0>", cmd = ":NvimTreeFindFileToggle<CR>" },
}
function M.plugin(api, opts)

View file

@ -28,3 +28,9 @@ end, {
desc = "Toggle autoformat-on-save (use ! for buffer-local)",
bang = true,
})
vim.api.nvim_create_user_command("Reload", function()
vim.cmd("luafile ~/.config/nvim/init.lua")
end, {
desc = "Reload Neovim configuration",
})

View file

@ -41,25 +41,6 @@ return {
})
end,
},
{
"nvim-orgmode/orgmode",
event = "VeryLazy",
ft = { "org" },
config = function()
-- Setup orgmode
require("orgmode").setup({
org_agenda_files = "~/orgfiles/**/*",
org_default_notes_file = "~/orgfiles/refile.org",
})
-- NOTE: If you are using nvim-treesitter with ~ensure_installed = "all"~ option
-- add ~org~ to ignore_install
-- require('nvim-treesitter.configs').setup({
-- ensure_installed = 'all',
-- ignore_install = { 'org' },
-- })
end,
},
{ import = "plugins.mod.conform-nvim" },
{ "nvim-treesitter/nvim-treesitter-context" },
{

View file

@ -0,0 +1,168 @@
local M = {}
local colors = require("config.colors")
local icons = require("config.icons")
local function diff_source()
local gitsigns = vim.b.gitsigns_status_dict
if gitsigns then
return {
added = gitsigns.added,
modified = gitsigns.changed,
removed = gitsigns.removed,
}
end
end
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand("%:t")) ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand("%:p:h")
local gitdir = vim.fn.finddir(".git", filepath .. ";")
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
local mode_color = {
n = colors.blue,
i = colors.green,
v = colors.magenta,
[""] = colors.magenta,
V = colors.magenta,
c = colors.magenta,
no = colors.red,
s = colors.orange,
S = colors.orange,
[""] = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
["r?"] = colors.cyan,
["!"] = colors.red,
t = colors.red,
}
local mode_color_bg = function()
return { fg = colors.bg, bg = mode_color[vim.fn.mode()] }
end
-- local mode_color_fg = function()
-- return { fg = mode_color[vim.fn.mode()] }
-- end
M.mode = {
function()
return ""
end,
color = mode_color_bg,
}
M.git = {
"branch",
icon = icons.git.Branch,
color = { fg = colors.violet, gui = "bold" },
}
M.diagnostics = {
"diagnostics",
sources = { "nvim_diagnostic" },
symbols = {
error = icons.diagnostics.Error .. " ",
warn = icons.diagnostics.Warning .. " ",
info = icons.diagnostics.Information .. " ",
hint = icons.diagnostics.Hint .. " ",
},
}
M.lsp = {
-- Lsp server name .
function()
local msg = "LSP Inactive"
local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = 0 })
local clients = vim.lsp.get_clients()
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
return client.name
end
end
return msg
end,
icon = icons.lsp,
color = { fg = colors.yellow, gui = "italic" },
}
M.filetype = {
function()
return vim.bo.filetype
end,
color = { fg = colors.blue, gui = "bold" },
}
M.eol = {
function()
return vim.bo.eol == true and icons.eol or ""
end,
color = { fg = colors.red },
}
M.command = {
"command",
color = { fg = colors.green, gui = "bold" },
}
M.encoding = {
"o:encoding",
color = { fg = colors.green, gui = "bold" },
}
M.indent = {
function()
local shiftwidth = vim.api.nvim_get_option_value("shiftwidth", { buf = 0 })
return icons.indent .. " " .. shiftwidth
end,
padding = 1,
}
-- M.diff = {
-- "diff",
-- -- Is it me or the symbol for modified us really weird
-- symbols = { added = " ", modified = "󰝤 ", removed = " " },
-- diff_color = {
-- added = { fg = colors.green },
-- modified = { fg = colors.orange },
-- removed = { fg = colors.red },
-- },
-- cond = conditions.hide_in_width,
-- }
M.diff = {
"diff",
source = diff_source,
-- symbols = { added = " ", modified = "󰝤 ", removed = " " },
symbols = {
added = icons.git.Add .. " ",
modified = icons.git.Change .. " ",
removed = icons.git.Delete .. " ",
},
padding = { left = 2, right = 1 },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.yellow },
removed = { fg = colors.red },
},
cond = nil,
}
M.progress = { "progress", color = mode_color_bg }
return M

View file

@ -1,34 +1,9 @@
local lualine = require("lualine")
-- Color table for highlights
-- stylua: ignore
local colors = {
bg = '#202328',
fg = '#bbc2cf',
yellow = '#ECBE7B',
cyan = '#008080',
darkblue = '#081633',
green = '#98be65',
orange = '#FF8800',
violet = '#a9a1e1',
magenta = '#c678dd',
blue = '#51afef',
red = '#ec5f67',
}
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand("%:t")) ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand("%:p:h")
local gitdir = vim.fn.finddir(".git", filepath .. ";")
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
local colors = require("plugins.mod.lualine.colors")
local components = require("plugins.mod.lualine.components")
-- Config
local config = {
@ -78,157 +53,21 @@ local function ins_right(component)
table.insert(config.sections.lualine_x, component)
end
ins_left({
function()
return ""
end,
color = { fg = colors.blue }, -- Sets highlighting of component
padding = { left = 0, right = 1 }, -- We don't need space before this
})
--[[
VSCode Style:
Remote | Git Branch | Diagnostics | Command | | MID | | Line:Column | Indent | Encoding | EOL | File Type LSP | Notifications
--]]
ins_left({
-- mode component
function()
return ""
end,
color = function()
-- auto change color according to neovims mode
local mode_color = {
n = colors.red,
i = colors.green,
v = colors.blue,
[""] = colors.blue,
V = colors.blue,
c = colors.magenta,
no = colors.red,
s = colors.orange,
S = colors.orange,
[""] = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
["r?"] = colors.cyan,
["!"] = colors.red,
t = colors.red,
}
return { fg = mode_color[vim.fn.mode()] }
end,
padding = { right = 1 },
})
ins_left(components.mode)
ins_left(components.diff)
ins_left(components.git)
ins_left(components.diagnostics)
ins_left(components.command)
ins_right(components.indent)
ins_right(components.encoding)
ins_right(components.eol)
ins_right(components.filetype)
ins_right(components.lsp)
ins_right(components.progress)
-- ins_left {
-- -- filesize component
-- 'filesize',
-- cond = conditions.buffer_not_empty,
-- }
-- ins_left {
-- 'filename',
-- cond = conditions.buffer_not_empty,
-- color = { fg = colors.magenta, gui = 'bold' },
-- }
-- ins_left { 'location' }
ins_right({ "progress", color = { fg = colors.fg, gui = "bold" } })
ins_left({
"diagnostics",
sources = { "nvim_diagnostic" },
symbols = { error = "", warn = "", info = "" },
diagnostics_color = {
error = { fg = colors.red },
warn = { fg = colors.yellow },
info = { fg = colors.cyan },
},
})
ins_left({
function()
return vim.bo.filetype
end,
color = { fg = colors.blue, gui = "bold" },
})
ins_left({
function()
return vim.bo.shiftwidth .. " space"
end,
})
ins_left({
-- Lsp server name .
function()
local msg = "No Active Lsp"
local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = 0 })
local clients = vim.lsp.get_clients()
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
return client.name
end
end
return msg
end,
icon = "",
color = { fg = "#ffffff", gui = "bold" },
})
-- Insert mid section. You can make any number of sections in neovim :)
-- for lualine it's any number greater then 2
ins_left({
function()
return "%="
end,
})
-- Add components to right sections
ins_right({
"o:encoding", -- option component same as &encoding in viml
fmt = string.upper, -- I'm not sure why it's upper case either ;)
cond = conditions.hide_in_width,
color = { fg = colors.green, gui = "bold" },
})
ins_right({
"fileformat",
fmt = string.upper,
icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh
color = { fg = colors.green, gui = "bold" },
})
ins_right({
"branch",
icon = "",
color = { fg = colors.violet, gui = "bold" },
})
ins_right({
"diff",
-- Is it me or the symbol for modified us really weird
symbols = { added = "", modified = "󰝤 ", removed = "" },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.orange },
removed = { fg = colors.red },
},
cond = conditions.hide_in_width,
})
ins_right({
function()
return ""
end,
color = { fg = colors.blue },
padding = { left = 1 },
})
-- Now don't forget to initialize lualine
lualine.setup(config)

View file

@ -65,7 +65,7 @@ local os_type = detect_os()
config.max_fps = 120
config.font = wezterm.font({
family = "CaskaydiaCove Nerd Font",
family = "JetBrainsMono Nerd Font",
})
config.color_scheme = "Catppuccin Mocha"
config.font_size = 12.0