init.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. -- if not package.loaded['galaxyline'] then
  2. -- return
  3. -- end
  4. local status_ok, gl = pcall(require, "galaxyline")
  5. if not status_ok then
  6. return
  7. end
  8. -- get my theme in galaxyline repo
  9. -- local colors = require('galaxyline.theme').default
  10. local colors = {
  11. bg = "#2E2E2E",
  12. -- bg = '#292D38',
  13. yellow = "#DCDCAA",
  14. dark_yellow = "#D7BA7D",
  15. cyan = "#4EC9B0",
  16. green = "#608B4E",
  17. light_green = "#B5CEA8",
  18. string_orange = "#CE9178",
  19. orange = "#FF8800",
  20. purple = "#C586C0",
  21. magenta = "#D16D9E",
  22. grey = "#858585",
  23. blue = "#569CD6",
  24. vivid_blue = "#4FC1FF",
  25. light_blue = "#9CDCFE",
  26. red = "#D16969",
  27. error_red = "#F44747",
  28. info_yellow = "#FFCC66",
  29. }
  30. local condition = require "galaxyline.condition"
  31. local gls = gl.section
  32. gl.short_line_list = { "NvimTree", "vista", "dbui", "packer" }
  33. table.insert(gls.left, {
  34. ViMode = {
  35. provider = function()
  36. -- auto change color according the vim mode
  37. local mode_color = {
  38. n = colors.blue,
  39. i = colors.green,
  40. v = colors.purple,
  41. [""] = colors.purple,
  42. V = colors.purple,
  43. c = colors.magenta,
  44. no = colors.blue,
  45. s = colors.orange,
  46. S = colors.orange,
  47. [""] = colors.orange,
  48. ic = colors.yellow,
  49. R = colors.red,
  50. Rv = colors.red,
  51. cv = colors.blue,
  52. ce = colors.blue,
  53. r = colors.cyan,
  54. rm = colors.cyan,
  55. ["r?"] = colors.cyan,
  56. ["!"] = colors.blue,
  57. t = colors.blue,
  58. }
  59. vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()])
  60. return "▊"
  61. end,
  62. separator_highlight = "StatusLineSeparator",
  63. highlight = "StatusLineNC",
  64. },
  65. })
  66. -- print(vim.fn.getbufvar(0, 'ts'))
  67. vim.fn.getbufvar(0, "ts")
  68. table.insert(gls.left, {
  69. GitIcon = {
  70. provider = function()
  71. return " "
  72. end,
  73. condition = condition.check_git_workspace,
  74. separator = " ",
  75. separator_highlight = "StatusLineSeparator",
  76. highlight = "StatusLineGit",
  77. },
  78. })
  79. table.insert(gls.left, {
  80. GitBranch = {
  81. provider = "GitBranch",
  82. condition = condition.check_git_workspace,
  83. separator = " ",
  84. separator_highlight = "StatusLineSeparator",
  85. highlight = "StatusLineNC",
  86. },
  87. })
  88. table.insert(gls.left, {
  89. DiffAdd = {
  90. provider = "DiffAdd",
  91. condition = condition.hide_in_width,
  92. icon = "  ",
  93. highlight = "StatusLineGitAdd",
  94. },
  95. })
  96. table.insert(gls.left, {
  97. DiffModified = {
  98. provider = "DiffModified",
  99. condition = condition.hide_in_width,
  100. icon = " 柳",
  101. highlight = "StatusLineGitChange",
  102. },
  103. })
  104. table.insert(gls.left, {
  105. DiffRemove = {
  106. provider = "DiffRemove",
  107. condition = condition.hide_in_width,
  108. icon = "  ",
  109. highlight = "StatusLineGitDelete",
  110. },
  111. })
  112. table.insert(gls.left, {
  113. Filler = {
  114. provider = function()
  115. return " "
  116. end,
  117. highlight = "StatusLineGitDelete",
  118. },
  119. })
  120. -- get output from shell command
  121. function os.capture(cmd, raw)
  122. local f = assert(io.popen(cmd, 'r'))
  123. local s = assert(f:read('*a'))
  124. f:close()
  125. if raw then return s end
  126. s = string.gsub(s, '^%s+', '')
  127. s = string.gsub(s, '%s+$', '')
  128. s = string.gsub(s, '[\n\r]+', ' ')
  129. return s
  130. end
  131. -- cleanup virtual env
  132. function env_cleanup(venv)
  133. if string.find(venv, "/") then
  134. final_venv = venv
  135. for w in venv:gmatch("([^/]+)") do final_venv=w end
  136. venv = final_venv
  137. end
  138. return venv
  139. end
  140. local PythonEnv = function ()
  141. if vim.bo.filetype == 'python' then
  142. venv = os.getenv('CONDA_DEFAULT_ENV')
  143. if venv ~= nil then
  144. return "🅒 " .. env_cleanup(venv)
  145. end
  146. venv = os.getenv('VIRTUAL_ENV')
  147. if venv ~= nil then
  148. return "🐍 " .. env_cleanup(venv)
  149. end
  150. return ''
  151. end
  152. return ''
  153. end
  154. table.insert(gls.left, {
  155. VirtualEnv = {
  156. provider = PythonEnv,
  157. highlight = {colors.green, colors.bg},
  158. event = 'BufEnter'
  159. }
  160. })
  161. table.insert(gls.right, {
  162. DiagnosticError = {
  163. provider = "DiagnosticError",
  164. icon = "  ",
  165. highlight = "StatusLineLspDiagnosticsError",
  166. },
  167. })
  168. table.insert(gls.right, {
  169. DiagnosticWarn = {
  170. provider = "DiagnosticWarn",
  171. icon = "  ",
  172. highlight = "StatusLineLspDiagnosticsWarning",
  173. },
  174. })
  175. table.insert(gls.right, {
  176. DiagnosticInfo = {
  177. provider = "DiagnosticInfo",
  178. icon = "  ",
  179. highlight = "StatusLineLspDiagnosticsInformation",
  180. },
  181. })
  182. table.insert(gls.right, {
  183. DiagnosticHint = {
  184. provider = "DiagnosticHint",
  185. icon = "  ",
  186. highlight = "StatusLineLspDiagnosticsHint",
  187. },
  188. })
  189. table.insert(gls.right, {
  190. TreesitterIcon = {
  191. provider = function()
  192. if next(vim.treesitter.highlighter.active) ~= nil then
  193. return " "
  194. end
  195. return ""
  196. end,
  197. separator = " ",
  198. separator_highlight = "StatusLineSeparator",
  199. highlight = "StatusLineTreeSitter",
  200. },
  201. })
  202. local get_lsp_client = function(msg)
  203. msg = msg or "LSP Inactive"
  204. local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
  205. local clients = vim.lsp.get_active_clients()
  206. if next(clients) == nil then
  207. return msg
  208. end
  209. local lsps = ""
  210. for _, client in ipairs(clients) do
  211. local filetypes = client.config.filetypes
  212. if filetypes and vim.fn.index(filetypes, buf_ft) ~= 1 then
  213. -- print(client.name)
  214. if lsps == "" then
  215. -- print("first", lsps)
  216. lsps = client.name
  217. else
  218. lsps = lsps .. ", " .. client.name
  219. -- print("more", lsps)
  220. end
  221. end
  222. end
  223. if lsps == "" then
  224. return msg
  225. else
  226. return lsps
  227. end
  228. end
  229. table.insert(gls.right, {
  230. ShowLspClient = {
  231. provider = get_lsp_client,
  232. condition = function()
  233. local tbl = { ["dashboard"] = true, [" "] = true }
  234. if tbl[vim.bo.filetype] then
  235. return false
  236. end
  237. return true
  238. end,
  239. icon = " ",
  240. highlight = "StatusLineNC",
  241. },
  242. })
  243. table.insert(gls.right, {
  244. LineInfo = {
  245. provider = "LineColumn",
  246. separator = " ",
  247. separator_highlight = "StatusLineSeparator",
  248. highlight = "StatusLineNC",
  249. },
  250. })
  251. table.insert(gls.right, {
  252. PerCent = {
  253. provider = "LinePercent",
  254. separator = " ",
  255. separator_highlight = "StatusLineSeparator",
  256. highlight = "StatusLineNC",
  257. },
  258. })
  259. table.insert(gls.right, {
  260. Tabstop = {
  261. provider = function()
  262. return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
  263. end,
  264. condition = condition.hide_in_width,
  265. separator = " ",
  266. separator_highlight = "StatusLineSeparator",
  267. highlight = "StatusLineNC",
  268. },
  269. })
  270. table.insert(gls.right, {
  271. BufferType = {
  272. provider = "FileTypeName",
  273. condition = condition.hide_in_width,
  274. separator = " ",
  275. separator_highlight = "StatusLineSeparator",
  276. highlight = "StatusLineNC",
  277. },
  278. })
  279. table.insert(gls.right, {
  280. FileEncode = {
  281. provider = "FileEncode",
  282. condition = condition.hide_in_width,
  283. separator = " ",
  284. separator_highlight = "StatusLineSeparator",
  285. highlight = "StatusLineNC",
  286. },
  287. })
  288. table.insert(gls.right, {
  289. Space = {
  290. provider = function()
  291. return " "
  292. end,
  293. separator = " ",
  294. separator_highlight = "StatusLineSeparator",
  295. highlight = "StatusLineNC",
  296. },
  297. })
  298. table.insert(gls.short_line_left, {
  299. BufferType = {
  300. provider = "FileTypeName",
  301. separator = " ",
  302. separator_highlight = "StatusLineSeparator",
  303. highlight = "StatusLineNC",
  304. },
  305. })
  306. table.insert(gls.short_line_left, {
  307. SFileName = {
  308. provider = "SFileName",
  309. condition = condition.buffer_not_empty,
  310. highlight = "StatusLineNC",
  311. },
  312. })
  313. --table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.bg}}})