init.lua 7.1 KB

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