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.

279 lines
7.0 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. ins_right {
  180. 'copilot',
  181. show_colors = true,
  182. show_loading = true
  183. }
  184. -- Add components to right sections
  185. ins_right {
  186. 'o:encoding', -- option component same as &encoding in viml
  187. fmt = string.upper, -- I'm not sure why it's upper case either ;)
  188. cond = conditions.hide_in_width,
  189. color = { fg = colors.green, gui = 'bold' },
  190. }
  191. ins_right {
  192. 'fileformat',
  193. fmt = string.upper,
  194. icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh
  195. color = { fg = colors.green, gui = 'bold' },
  196. }
  197. ins_right {
  198. 'branch',
  199. icon = '',
  200. color = { fg = colors.violet, gui = 'bold' },
  201. }
  202. ins_right {
  203. 'diff',
  204. -- Is it me or the symbol for modified us really weird
  205. symbols = { added = '', modified = '󰝤 ', removed = '' },
  206. diff_color = {
  207. added = { fg = colors.green },
  208. modified = { fg = colors.orange },
  209. removed = { fg = colors.red },
  210. },
  211. cond = conditions.hide_in_width,
  212. }
  213. ins_right {
  214. function()
  215. return ''
  216. end,
  217. color = { fg = colors.blue },
  218. padding = { left = 1 },
  219. }
  220. local lualine = require("lualine");
  221. vim.api.nvim_create_autocmd("RecordingEnter", {
  222. callback = function()
  223. lualine.refresh({
  224. place = { "statusline" },
  225. })
  226. end,
  227. })
  228. vim.api.nvim_create_autocmd("RecordingLeave", {
  229. callback = function()
  230. -- This is going to seem really weird!
  231. -- Instead of just calling refresh we need to wait a moment because of the nature of
  232. -- `vim.fn.reg_recording`. If we tell lualine to refresh right now it actually will
  233. -- still show a recording occuring because `vim.fn.reg_recording` hasn't emptied yet.
  234. -- So what we need to do is wait a tiny amount of time (in this instance 50 ms) to
  235. -- ensure `vim.fn.reg_recording` is purged before asking lualine to refresh.
  236. local timer = vim.loop.new_timer()
  237. timer:start(
  238. 50,
  239. 0,
  240. vim.schedule_wrap(function()
  241. lualine.refresh({
  242. place = { "statusline" },
  243. })
  244. end)
  245. )
  246. end,
  247. })
  248. lualine.setup(config)
  249. end
  250. return config