Last active
July 12, 2022 06:30
-
-
Save horseinthesky/87d6f5dc8d118b294f35ece4121cf06d to your computer and use it in GitHub Desktop.
galaxyline.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local gl = require "galaxyline" | |
local vcs = require "galaxyline.providers.vcs" | |
local condition = require "galaxyline.condition" | |
local devicons = require "nvim-web-devicons" | |
local utils = require "utils" | |
local appearance = require "appearance" | |
local icons = appearance.icons | |
local theme_map = appearance.color_map[vim.g.colors_name] or appearance.color_map["gruvbox"] | |
local colors = theme_map[vim.opt.background:get()] or theme_map["dark"] | |
gl.short_line_list = { | |
"packer", | |
"Outline", | |
"Mundo", | |
"MundoDiff", | |
"startify", | |
"startuptime", | |
} | |
local mode_map = { | |
n = { "", "NORMAL" }, | |
i = { "", "INSERT" }, | |
ic = { "", "INSERT" }, | |
R = { "", "REPLACE" }, | |
v = { "", "VISUAL" }, | |
V = { "", "V-LINE" }, | |
c = { "ﲵ", "COMMAND" }, | |
s = { "", "SELECT" }, | |
S = { "", "S-LINE" }, | |
t = { "", "TERMINAL" }, | |
nt = { "", "TERMINAL" }, | |
["\22"] = { "", "V-BLOCK" }, | |
["\19"] = { "", "S-BLOCK" }, | |
} | |
setmetatable(mode_map, { | |
__index = function() | |
return { icons.question, utils.get_current_mode() } | |
end, | |
}) | |
local function diag(severity) | |
local count = vim.lsp.diagnostic.get_count(0, severity) | |
if count == 0 then | |
return "" | |
end | |
local diag_mapping = { | |
Warning = icons.diagnostic.warning, | |
Error = icons.diagnostic.error, | |
Information = icons.diagnostic.info, | |
Hint = icons.diagnostic.hint, | |
} | |
return string.format(" %s %d ", diag_mapping[severity], count) | |
end | |
local gls = gl.section | |
gls.left[1] = { | |
ViMode = { | |
provider = function() | |
local icon, label = unpack(mode_map[utils.get_current_mode()]) | |
local fg, nested_fg = unpack(colors[utils.get_current_mode()]) | |
utils.highlight("GalaxyViMode", nested_fg, fg) | |
utils.highlight("GalaxyViModeInv", fg, nested_fg) | |
utils.highlight("GalaxyViModeNested", fg, nested_fg) | |
utils.highlight("GalaxyViModeInvNested", nested_fg, colors.substrate) | |
local mode = " " .. icon .. " " .. label .. " " | |
if vim.o.paste then | |
mode = mode .. icons.sep.left .. " " .. icons.paste .. " Paste " | |
end | |
return mode | |
end, | |
separator = icons.sep.left_filled, | |
separator_highlight = "GalaxyViModeInv", | |
}, | |
} | |
gls.left[2] = { | |
FileIcon = { | |
provider = function() | |
local extension = vim.fn.expand "%:e" | |
local icon, iconhl = devicons.get_icon(extension) | |
if icon == nil then | |
return "" | |
end | |
local fg = vim.fn.synIDattr(vim.api.nvim_get_hl_id_by_name(iconhl), "fg") | |
local _, bg = unpack(colors[utils.get_current_mode()]) | |
utils.highlight("GalaxyFileIcon", fg, bg) | |
return " " .. icon .. " " | |
end, | |
condition = utils.buffer_not_empty, | |
}, | |
} | |
gls.left[3] = { | |
FileName = { | |
provider = function() | |
if vim.bo.buftype == "terminal" then | |
return "" | |
end | |
if not utils.buffer_not_empty() then | |
return "" | |
end | |
local fname | |
if utils.wide_enough(140) then | |
fname = vim.fn.fnamemodify(vim.fn.expand "%", ":~:.") | |
if #fname > 35 then | |
fname = vim.fn.expand "%:t" | |
end | |
else | |
fname = vim.fn.expand "%:t" | |
end | |
if #fname == 0 then | |
return "" | |
end | |
if vim.bo.readonly then | |
fname = fname .. " " .. icons.file.locked | |
end | |
if not vim.bo.modifiable then | |
fname = fname .. " " .. icons.file.not_modifiable | |
end | |
if vim.bo.modified then | |
fname = fname .. " " .. icons.file.modified | |
end | |
return " " .. fname .. " " | |
end, | |
highlight = "GalaxyViModeNested", | |
condition = utils.buffer_not_empty, | |
}, | |
} | |
gls.left[4] = { | |
LeftSep = { | |
provider = function() | |
return icons.sep.left_filled | |
end, | |
highlight = "GalaxyViModeInvNested", | |
}, | |
} | |
gls.left[5] = { | |
GitIcon = { | |
provider = function() | |
local branch = vcs.get_git_branch() | |
if utils.wide_enough(95) and branch ~= nil then | |
return " " .. icons.git.branch .. " " | |
end | |
return "" | |
end, | |
highlight = { colors.git_icon, colors.substrate }, | |
}, | |
} | |
gls.left[6] = { | |
GitBranch = { | |
provider = function() | |
local branch = vcs.get_git_branch() | |
if utils.wide_enough(95) and branch ~= nil then | |
return branch .. " " | |
end | |
return "" | |
end, | |
highlight = { colors.git_branch, colors.substrate }, | |
}, | |
} | |
gls.left[7] = { | |
DiffAdd = { | |
provider = function() | |
if condition.check_git_workspace() and utils.wide_enough(120) then | |
return vcs.diff_add() | |
end | |
return "" | |
end, | |
icon = icons.circle.plus .. " ", | |
highlight = { colors.diff_add, colors.substrate }, | |
}, | |
} | |
gls.left[8] = { | |
DiffModified = { | |
provider = function() | |
if condition.check_git_workspace() and utils.wide_enough(120) then | |
return vcs.diff_modified() | |
end | |
return "" | |
end, | |
icon = icons.circle.dot .. " ", | |
highlight = { colors.diff_modified, colors.substrate }, | |
}, | |
} | |
gls.left[9] = { | |
DiffRemove = { | |
provider = function() | |
if condition.check_git_workspace() and utils.wide_enough(120) then | |
return vcs.diff_remove() | |
end | |
return "" | |
end, | |
icon = icons.circle.minus .. " ", | |
highlight = { colors.diff_remove, colors.substrate }, | |
}, | |
} | |
gls.right[1] = { | |
LspIcon = { | |
provider = function() | |
if utils.wide_enough(85) and utils.diagnostic_exists() then | |
return icons.gears .. " " | |
end | |
end, | |
highlight = { colors.lsp_icon, colors.substrate }, | |
}, | |
} | |
gls.right[2] = { | |
LspServer = { | |
provider = function() | |
if utils.wide_enough(85) and utils.diagnostic_exists() then | |
local clients = utils.get_lsp_clients() | |
return clients .. " " | |
end | |
end, | |
highlight = { colors.lsp_name, colors.substrate }, | |
}, | |
} | |
gls.right[3] = { | |
DiagnosticOk = { | |
provider = function() | |
if not utils.wide_enough(85) or not utils.diagnostic_exists() then | |
return "" | |
end | |
local w = vim.lsp.diagnostic.get_count(0, "Warning") | |
local e = vim.lsp.diagnostic.get_count(0, "Error") | |
local i = vim.lsp.diagnostic.get_count(0, "Information") | |
local h = vim.lsp.diagnostic.get_count(0, "Hint") | |
if w ~= 0 or e ~= 0 or i ~= 0 or h ~= 0 then | |
return "" | |
end | |
return icons.diagnostic.ok .. " " | |
end, | |
highlight = { colors.ok, colors.substrate }, | |
}, | |
} | |
gls.right[4] = { | |
DiagnosticError = { | |
provider = function() | |
return diag "Error" | |
end, | |
highlight = { colors.error, colors.substrate }, | |
}, | |
} | |
gls.right[5] = { | |
DiagnosticWarn = { | |
provider = function() | |
return diag "Warning" | |
end, | |
highlight = { colors.warn, colors.substrate }, | |
}, | |
} | |
gls.right[6] = { | |
DiagnosticHint = { | |
provider = function() | |
return diag "Hint" | |
end, | |
highlight = { colors.hint, colors.substrate }, | |
}, | |
} | |
gls.right[7] = { | |
DiagnosticInfo = { | |
provider = function() | |
return diag "Information" | |
end, | |
highlight = { colors.info, colors.substrate }, | |
}, | |
} | |
gls.right[8] = { | |
RightSepNested = { | |
provider = function() | |
return icons.sep.right_filled | |
end, | |
highlight = "GalaxyViModeInvNested", | |
}, | |
} | |
gls.right[9] = { | |
FileFormat = { | |
provider = function() | |
if not utils.buffer_not_empty() or not utils.wide_enough(80) then | |
return "" | |
end | |
local icon = icons[vim.bo.fileformat] or "" | |
return string.format(" %s %s ", icon, vim.bo.fileencoding) | |
end, | |
highlight = "GalaxyViModeNested", | |
}, | |
} | |
gls.right[10] = { | |
RightSep = { | |
provider = function() | |
return icons.sep.right_filled | |
end, | |
highlight = "GalaxyViModeInv", | |
}, | |
} | |
gls.right[11] = { | |
PositionInfo = { | |
provider = function() | |
if not utils.buffer_not_empty() or not utils.wide_enough(70) then | |
return "" | |
end | |
return string.format(" %s %s:%s ", icons.line_number, unpack(vim.api.nvim_win_get_cursor(0))) | |
end, | |
highlight = "GalaxyViMode", | |
}, | |
} | |
gls.right[12] = { | |
PercentInfo = { | |
provider = function() | |
if not utils.buffer_not_empty() or not utils.wide_enough(75) then | |
return "" | |
end | |
local curr_line = vim.api.nvim_win_get_cursor(0)[1] | |
local lines = vim.api.nvim_buf_line_count(0) | |
return string.format(" %s %d%% ", icons.page, math.floor(100 * curr_line / lines)) | |
end, | |
highlight = "GalaxyViMode", | |
separator = icons.sep.right, | |
separator_highlight = "GalaxyViMode", | |
}, | |
} | |
local short_map = { | |
packer = "Packer", | |
Outline = "Outline", | |
Mundo = "History", | |
MundoDiff = "Diff", | |
startify = "Starfity", | |
startuptime = "StartupTime", | |
} | |
gls.short_line_left[1] = { | |
BufferType = { | |
provider = function() | |
local fg, nested_fg = unpack(colors[utils.get_current_mode()]) | |
utils.highlight("GalaxyViMode", nested_fg, fg) | |
utils.highlight("GalaxyViModeInv", fg, nested_fg) | |
utils.highlight("GalaxyViModeInvNested", nested_fg, colors.substrate) | |
local name = short_map[vim.bo.filetype] | |
if name == nil then | |
return "" | |
end | |
return string.format(" %s ", name) | |
end, | |
highlight = "GalaxyViMode", | |
condition = utils.has_filetype, | |
separator = icons.sep.left_filled, | |
separator_highlight = "GalaxyViModeInv", | |
}, | |
} | |
gls.short_line_left[2] = { | |
ShortLeftSepNested = { | |
provider = function() | |
return icons.sep.left_filled | |
end, | |
highlight = "GalaxyViModeInvNested", | |
}, | |
} | |
gls.short_line_right[1] = { | |
ShortRightSepNested = { | |
provider = function() | |
return icons.sep.right_filled | |
end, | |
highlight = "GalaxyViModeInvNested", | |
}, | |
} | |
gls.short_line_right[2] = { | |
ShortRightSep = { | |
provider = function() | |
return icons.sep.right_filled | |
end, | |
highlight = "GalaxyViModeInv", | |
}, | |
} |
Galaxyline API changed a little + I've changed it a bit also.
Check out actual config in my dotfiles
https://github.com/horseinthesky/dotfiles/blob/master/files/lua/statusline.lua
you will also need utils
https://github.com/horseinthesky/dotfiles/blob/master/files/lua/utils.lua
Thanks! I'm pretty new to lua and just wanted a standalone config so this works well :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
trying to use this gives me an error
attempt to call check_git_workspace ( a nil value)