From 3691d67298110b6cc842a1f63ab017e56d19ec3c Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Thu, 29 Oct 2020 10:22:53 +0530 Subject: [PATCH] nvim: Use galaxyline for statusline --- nvim/.config/nvim/lua/autocmd.lua | 12 -- nvim/.config/nvim/lua/modules/statusline.lua | 202 +++++++++++++++++++ nvim/.config/nvim/lua/plugins.lua | 7 + nvim/.config/nvim/plugin/statusline.vim | 67 ------ 4 files changed, 209 insertions(+), 79 deletions(-) create mode 100644 nvim/.config/nvim/lua/modules/statusline.lua delete mode 100644 nvim/.config/nvim/plugin/statusline.vim diff --git a/nvim/.config/nvim/lua/autocmd.lua b/nvim/.config/nvim/lua/autocmd.lua index f440518..bc13d3a 100644 --- a/nvim/.config/nvim/lua/autocmd.lua +++ b/nvim/.config/nvim/lua/autocmd.lua @@ -38,18 +38,6 @@ local autocmds = { { "FocusGained", "*", "silent! lua require('scrollbar').show()" }; { "FocusLost", "*", "silent! lua require('scrollbar').clear()" }; }; - user_status_line = { - { "BufEnter,WinEnter,TermOpen", "*", "setlocal statusline=%!ActiveStatus()" }; - { "WinLeave", "*", "setlocal statusline=%!PassiveStatus()" }; - { "ColorScheme", "*", "hi User1 guifg=DarkRed guibg=Black" }; - { "ColorScheme", "*", "hi User2 guifg=White guibg=Black" }; - { "ColorScheme", "*", "hi User3 guifg=Cyan guibg=Black" }; - { "ColorScheme", "*", "hi User4 guifg=Orange guibg=Black" }; - { "ColorScheme", "*", "hi User5 guifg=Red guibg=Black" }; - { "ColorScheme", "*", "hi User6 guifg=Gray guibg=Black" }; - { "ColorScheme", "*", "hi User7 guifg=Gray guibg=Black" }; - { "ColorScheme", "*", "hi User8 guifg=DarkYellow guibg=Black" }; - }; } nvim_create_augroups(autocmds) diff --git a/nvim/.config/nvim/lua/modules/statusline.lua b/nvim/.config/nvim/lua/modules/statusline.lua new file mode 100644 index 0000000..976c2a3 --- /dev/null +++ b/nvim/.config/nvim/lua/modules/statusline.lua @@ -0,0 +1,202 @@ +local lsp_status = require('lsp-status') +local gl = require('galaxyline') +local gls = gl.section + +local colors = { + line_bg = '#21242b', + bg = '#000000', + fg = '#c0c0c0', + yellow = '#fabd2f', + cyan = '#008080', + darkblue = '#081633', + green = '#afd700', + orange = '#FF8800', + purple = '#5d4d7a', + magenta = '#c678dd', + blue = '#51afef', + red = '#ec5f67' +} + +local buffer_not_empty = function() + if vim.fn.empty(vim.fn.expand('%:t')) ~= 1 then + return true + end + return false +end + +local checkwidth = function() + local squeeze_width = vim.fn.winwidth(0) / 2 + if squeeze_width > 40 then + return true + end + return false +end + +local function find_git_root() + local path = vim.fn.expand('%:p:h') + local get_git_dir = require('galaxyline.provider_vcs').get_git_dir + return get_git_dir(path) +end + +gls.left[1] = { + FirstElement = { + provider = function() return '▋' end, + highlight = { colors.bg, colors.line_bg } + }, +} +gls.left[2] = { + ViMode = { + provider = function() + local mode_color = { + n = colors.magenta, i = colors.green, v = colors.blue, [''] = colors.blue, V = colors.blue, + c = colors.red, no = colors.magenta, s = colors.orange, S = colors.orange, + [''] = colors.orange, ic = colors.yellow, R = colors.purple, Rv = colors.purple, + cv = colors.red, ce = colors.red, r = colors.cyan, rm = colors.cyan, ['r?'] = colors.cyan, + ['!'] = colors.red, t = colors.red + } + vim.api.nvim_command('hi GalaxyViMode guifg='..mode_color[vim.fn.mode()]) + return ' ' + end, + highlight = { colors.red, colors.line_bg, 'bold' }, + }, +} +gls.left[3] = { + FileIcon = { + provider = 'FileIcon', + condition = buffer_not_empty, + highlight = { require('galaxyline.provider_fileinfo').get_file_icon_color, colors.line_bg }, + }, +} +gls.left[4] = { + FileName = { + provider = {'FileName'}, + condition = buffer_not_empty, + highlight = { colors.fg, colors.line_bg, 'bold' } + } +} +gls.left[5] = { + GitIcon = { + provider = function() return '  ' end, + condition = find_git_root, + highlight = { colors.orange, colors.line_bg }, + } +} +gls.left[6] = { + GitBranch = { + provider = 'GitBranch', + condition = find_git_root, + highlight = { colors.fg, colors.line_bg, 'bold' }, + } +} +gls.left[7] = { + DiffAdd = { + provider = 'DiffAdd', + condition = checkwidth and find_git_root, + icon = ' ', + highlight = { colors.green, colors.line_bg }, + } +} +gls.left[8] = { + DiffModified = { + provider = 'DiffModified', + condition = checkwidth and find_git_root, + icon = ' ', + highlight = { colors.orange, colors.line_bg }, + } +} +gls.left[9] = { + DiffRemove = { + provider = 'DiffRemove', + condition = checkwidth and find_git_root, + icon = ' ', + highlight = { colors.red, colors.line_bg }, + } +} +gls.left[10] = { + LeftEnd = { + provider = function() return '' end, + separator = '', + separator_highlight = { colors.bg, colors.line_bg }, + highlight = { colors.line_bg, colors.line_bg } + } +} +gls.left[11] = { + DiagnosticError = { + provider = 'DiagnosticError', + icon = '  ', + highlight = { colors.red, colors.bg } + } +} +gls.left[12] = { + Space = { + provider = function () return ' ' end + } +} +gls.left[13] = { + DiagnosticWarn = { + provider = 'DiagnosticWarn', + icon = '  ', + highlight = { colors.blue, colors.bg }, + } +} +gls.left[14] = { + LspStatus = { + provider = function() + if #vim.lsp.buf_get_clients() > 0 then + return lsp_status.status() + end + end, + highlight = { colors.orange, colors.bg,'bold' }, + } +} + +gls.right[1]= { + FileFormat = { + provider = 'FileFormat', + separator = '', + separator_highlight = { colors.bg, colors.line_bg }, + highlight = { colors.fg, colors.line_bg }, + } +} +gls.right[2] = { + LineInfo = { + provider = 'LineColumn', + separator = ' | ', + separator_highlight = { colors.blue, colors.line_bg }, + highlight = { colors.fg, colors.line_bg }, + }, +} +gls.right[3] = { + PerCent = { + provider = 'LinePercent', + separator = '', + separator_highlight = { colors.line_bg, colors.line_bg }, + highlight = { colors.fg, colors.darkblue }, + } +} + +gls.short_line_left[1] = { + BufferType = { + provider = 'FileTypeName', + separator = ' ', + separator_highlight = { colors.purple, colors.bg }, + highlight = { colors.fg, colors.purple } + } +} +gls.short_line_left[2] = { + WindowNumber = { + provider = function() return vim.fn.winnr() end, + separator = '', + separator_highlight = { colors.purple, colors.bg }, + highlight = { colors.red, colors.bg } + } +} + +gls.short_line_right[1] = { + BufferIcon = { + provider = 'BufferIcon', + separator = '', + separator_highlight = { colors.purple, colors.bg }, + highlight = { colors.fg, colors.purple } + } +} diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 4ed4cfa..eb13ed4 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -156,6 +156,13 @@ local init = function () use 'lifepillar/pgsql.vim' use 'mtdl9/vim-log-highlighting' use 'martinda/Jenkinsfile-vim-syntax' + -- For statusline + use { + 'glepnir/galaxyline.nvim', + branch = 'main', + config = "require('modules.statusline')", + requires = { 'kyazdani42/nvim-web-devicons' } + } end return require('packer').startup(init) diff --git a/nvim/.config/nvim/plugin/statusline.vim b/nvim/.config/nvim/plugin/statusline.vim deleted file mode 100644 index b8c4d8d..0000000 --- a/nvim/.config/nvim/plugin/statusline.vim +++ /dev/null @@ -1,67 +0,0 @@ -hi User1 guifg=DarkRed guibg=Black -hi User2 guifg=White guibg=Black -hi User3 guifg=Cyan guibg=Black -hi User4 guifg=Orange guibg=Black -hi User5 guifg=Red guibg=Black -hi User6 guifg=Gray guibg=Black -hi User7 guifg=Gray guibg=Black -hi User8 guifg=DarkYellow guibg=Black - -" https://nest.pijul.com/tae/setup:master/ -function! GetCursorPosition() - if &buftype == '' - let l:position = getcurpos() - return l:position[1] . 'Ⲷ ' . l:position[2] . 'Ⲽ' - endif - - return &buftype ==# 'quickfix' - \ ? line('.') . '/' . line('$') - \ : '' -endfunction - -function! GetFileStatus() - if &buftype != '' - return '' - endif - - let l:file = expand('%:p') - let l:status = - \ (&readonly || (filereadable(l:file) && !filewritable(l:file)) - \ ? 'RO' - \ : '') - \ . (&modified ? '+m' : '') - return len(l:status) > 0 ? ' ' . l:status : '' -endfunction - -function! LspStatus() abort - if luaeval('#vim.lsp.buf_get_clients() > 0') - return luaeval("require('lsp-status').status()") - endif - return '' -endfunction - -function! ActiveStatus() abort - let statusline="" - let statusline.="%1*\ %{winnr()}\ " - let statusline.="%4*\ %{GetFileStatus()}" - let statusline.="%2*\ %Y\ " - let statusline.="%3*%<%f" - let statusline.="%4%\ %{LspStatus()}" - let statusline.="%=" - let statusline.="%4*\ %{GetCursorPosition()}\ (%3p%%)" - return statusline -endfunction - -function! PassiveStatus() abort - let statusline="" - let statusline.="%5*\ %{winnr()}\ " - let statusline.="%8*\ %{GetFileStatus()}" - let statusline.="%6*\ %Y\ " - let statusline.="%7*%<%f" - let statusline.="%8%\ %{LspStatus()}" - let statusline.="%=" - let statusline.="%8*\ %{GetCursorPosition()}\ (%3p%%)" - return statusline -endfunction - -set statusline=%!ActiveStatus()