Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
6.9 KiB

  1. -- Eviline config for lualine
  2. -- Author: shadmansaleh
  3. -- Credit: glepnir
  4. -- Color table for highlights
  5. -- stylua: ignore
  6. local colors = {
  7. bg = '#202328',
  8. fg = '#bbc2cf',
  9. yellow = '#ECBE7B',
  10. cyan = '#008080',
  11. darkblue = '#081633',
  12. green = '#98be65',
  13. orange = '#FF8800',
  14. violet = '#a9a1e1',
  15. magenta = '#c678dd',
  16. blue = '#51afef',
  17. red = '#ec5f67',
  18. }
  19. local function show_macro_recording()
  20. local recording_register = vim.fn.reg_recording()
  21. if recording_register == "" then
  22. return ""
  23. else
  24. return "Recording @" .. recording_register
  25. end
  26. end
  27. local conditions = {
  28. buffer_not_empty = function()
  29. return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
  30. end,
  31. hide_in_width = function()
  32. return vim.fn.winwidth(0) > 80
  33. end,
  34. check_git_workspace = function()
  35. local filepath = vim.fn.expand('%:p:h')
  36. local gitdir = vim.fn.finddir('.git', filepath .. ';')
  37. return gitdir and #gitdir > 0 and #gitdir < #filepath
  38. end,
  39. }
  40. -- Config
  41. local config = function()
  42. local config = {
  43. extensions = {'nvim-tree', 'nvim-dap-ui', 'aerial'},
  44. options = {
  45. -- Disable lualine in nvim-tree
  46. -- disabled_filetypes = { 'packer', 'NvimTree' },
  47. -- Disable sections and component separators
  48. component_separators = '',
  49. section_separators = '',
  50. theme = {
  51. -- We are going to use lualine_c an lualine_x as left and
  52. -- right section. Both are highlighted by c theme . So we
  53. -- are just setting default looks o statusline
  54. normal = { c = { fg = colors.fg, bg = colors.bg } },
  55. inactive = { c = { fg = colors.fg, bg = colors.bg } },
  56. },
  57. },
  58. sections = {
  59. -- these are to remove the defaults
  60. lualine_a = {},
  61. lualine_b = {},
  62. lualine_y = {},
  63. lualine_z = {},
  64. -- These will be filled later
  65. lualine_c = {},
  66. lualine_x = {},
  67. },
  68. inactive_sections = {
  69. -- these are to remove the defaults
  70. lualine_a = {},
  71. lualine_b = {},
  72. lualine_y = {},
  73. lualine_z = {},
  74. lualine_c = {},
  75. lualine_x = {},
  76. },
  77. }
  78. -- Inserts a component in lualine_c at left section
  79. local function ins_left(component)
  80. table.insert(config.sections.lualine_c, component)
  81. end
  82. -- Inserts a component in lualine_x at right section
  83. local function ins_right(component)
  84. table.insert(config.sections.lualine_x, component)
  85. end
  86. ins_left {
  87. function()
  88. return ''
  89. end,
  90. color = { fg = colors.blue }, -- Sets highlighting of component
  91. padding = { left = 0, right = 1 }, -- We don't need space before this
  92. }
  93. ins_left {
  94. -- mode component
  95. function()
  96. return ''
  97. end,
  98. color = function()
  99. -- auto change color according to neovims mode
  100. local mode_color = {
  101. n = colors.red,
  102. i = colors.green,
  103. v = colors.blue,
  104. [''] = colors.blue,
  105. V = colors.blue,
  106. c = colors.magenta,
  107. no = colors.red,
  108. s = colors.orange,
  109. S = colors.orange,
  110. [''] = colors.orange,
  111. ic = colors.yellow,
  112. R = colors.violet,
  113. Rv = colors.violet,
  114. cv = colors.red,
  115. ce = colors.red,
  116. r = colors.cyan,
  117. rm = colors.cyan,
  118. ['r?'] = colors.cyan,
  119. ['!'] = colors.red,
  120. t = colors.red,
  121. }
  122. return { fg = mode_color[vim.fn.mode()] }
  123. end,
  124. padding = { right = 1 },
  125. }
  126. ins_left {
  127. -- filesize component
  128. 'filesize',
  129. cond = conditions.buffer_not_empty,
  130. }
  131. ins_left {
  132. 'macro-recording',
  133. fmt = show_macro_recording,
  134. }
  135. ins_left {
  136. 'filename',
  137. cond = conditions.buffer_not_empty,
  138. color = { fg = colors.magenta, gui = 'bold' },
  139. }
  140. ins_left { 'location' }
  141. ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } }
  142. ins_left {
  143. 'diagnostics',
  144. sources = { 'nvim_diagnostic' },
  145. symbols = { error = '', warn = '', info = '' },
  146. diagnostics_color = {
  147. color_error = { fg = colors.red },
  148. color_warn = { fg = colors.yellow },
  149. color_info = { fg = colors.cyan },
  150. },
  151. }
  152. -- Insert mid section. You can make any number of sections in neovim :)
  153. -- for lualine it's any number greater then 2
  154. ins_left {
  155. function()
  156. return '%='
  157. end,
  158. }
  159. ins_left {
  160. -- Lsp server name .
  161. function()
  162. local msg = 'No Active Lsp'
  163. local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype')
  164. local clients = vim.lsp.get_active_clients()
  165. if next(clients) == nil then
  166. return msg
  167. end
  168. for _, client in ipairs(clients) do
  169. local filetypes = client.config.filetypes
  170. if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
  171. return client.name
  172. end
  173. end
  174. return msg
  175. end,
  176. icon = ' LSP:',
  177. color = { fg = '#ffffff', gui = 'bold' },
  178. }
  179. -- Add components to right sections
  180. ins_right {
  181. 'o:encoding', -- option component same as &encoding in viml
  182. fmt = string.upper, -- I'm not sure why it's upper case either ;)
  183. cond = conditions.hide_in_width,
  184. color = { fg = colors.green, gui = 'bold' },
  185. }
  186. ins_right {
  187. 'fileformat',
  188. fmt = string.upper,
  189. icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh
  190. color = { fg = colors.green, gui = 'bold' },
  191. }
  192. ins_right {
  193. 'branch',
  194. icon = '',
  195. color = { fg = colors.violet, gui = 'bold' },
  196. }
  197. ins_right {
  198. 'diff',
  199. -- Is it me or the symbol for modified us really weird
  200. symbols = { added = '', modified = '󰝤 ', removed = '' },
  201. diff_color = {
  202. added = { fg = colors.green },
  203. modified = { fg = colors.orange },
  204. removed = { fg = colors.red },
  205. },
  206. cond = conditions.hide_in_width,
  207. }
  208. ins_right {
  209. function()
  210. return ''
  211. end,
  212. color = { fg = colors.blue },
  213. padding = { left = 1 },
  214. }
  215. local lualine = require("lualine");
  216. vim.api.nvim_create_autocmd("RecordingEnter", {
  217. callback = function()
  218. lualine.refresh({
  219. place = { "statusline" },
  220. })
  221. end,
  222. })
  223. vim.api.nvim_create_autocmd("RecordingLeave", {
  224. callback = function()
  225. -- This is going to seem really weird!
  226. -- Instead of just calling refresh we need to wait a moment because of the nature of
  227. -- `vim.fn.reg_recording`. If we tell lualine to refresh right now it actually will
  228. -- still show a recording occuring because `vim.fn.reg_recording` hasn't emptied yet.
  229. -- So what we need to do is wait a tiny amount of time (in this instance 50 ms) to
  230. -- ensure `vim.fn.reg_recording` is purged before asking lualine to refresh.
  231. local timer = vim.loop.new_timer()
  232. timer:start(
  233. 50,
  234. 0,
  235. vim.schedule_wrap(function()
  236. lualine.refresh({
  237. place = { "statusline" },
  238. })
  239. end)
  240. )
  241. end,
  242. })
  243. lualine.setup(config)
  244. end
  245. return config