Last active
October 29, 2023 19:11
-
-
Save deomorxsy/d3bcd27bf65f6122080960ff3c509c9f to your computer and use it in GitHub Desktop.
simple nvim lua statusline, old version, lil broken
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
vim.opt.laststatus = 2 | |
vim.opt.statusline = sl_values | |
-- local sl_values | |
-- statusline functions | |
local function StatuslineMode() | |
local mode = vim.fn.mode() | |
if mode == 'n' then | |
return "NORMAL" | |
elseif mode == 'v' then | |
return "VISUAL" | |
elseif mode == 'i' then | |
return "INSERT" | |
elseif mode == 'R' then | |
return "REPLACE" | |
end | |
return mode | |
end | |
local function StatuslineGitBranch() | |
local gitbranch = "" | |
if vim.bo.modifiable then | |
local current_dir = vim.fn.expand("%:p:h") | |
vim.cmd("lcd " .. current_dir) | |
local gitrevparse = vim.fn.system("git rev-parse --abbrev-ref HEAD") | |
vim.cmd("lcd -") | |
if not string.find(gitrevparse, "fatal: not a git repository") then | |
gitbranch = "(" .. string.gsub(gitrevparse, '\n', '') .. ") " | |
end | |
end | |
vim.bo.gitbranch = gitbranch | |
end | |
local sl_values = [[ | |
"", -- left align | |
"%2*\\", -- blank char | |
"%2*\\%{StatuslineMode()}", | |
"%2*\\", | |
"%1*\\ <<", | |
"%1*\\ %f", -- short filename | |
"%1*\\ >>", | |
"%=", -- right align | |
"%*", | |
"%3*\\%h%m%r", -- file flags (help, read-only, modified) | |
"%4*\\%{vim.b.gitbranch}", -- include git branch | |
"%3*\\%.25F", -- long filename (trimmed to 25 chars) | |
"%3*\\::", | |
"%3*\\%l/%L\\\\|", -- line count | |
"%3*\\%y" -- file type | |
]] | |
-- highlights | |
vim.cmd[[ | |
hi User1 ctermbg=black ctermfg=grey guibg=black guifg=grey | |
hi User2 ctermbg=green ctermfg=black guibg=green guifg=black | |
hi User3 ctermbg=black ctermfg=lightgreen guibg=black guifg=lightgreen | |
]] | |
local ggb_au = vim.api.nvim_create_augroup('get_git_branch', { clear = true}) | |
local function branch_name() | |
local branch = vim.fn.system("git branch --slow-current 2> /dev/null | tr -d '\n'") | |
if branch ~= "" then | |
return branch | |
else | |
return "" | |
end | |
end | |
vim.api.nvim_create_autocmd({"VimEnter","WinEnter","BufEnter"}, { | |
callback = function() | |
vim.b.branch_name = branch_name() | |
end | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment