theme.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. local M = {}
  2. function M.sync_theme()
  3. -- Use vim.fn.system for more reliable command execution in Neovim
  4. local result = vim.fn.system("gsettings get org.gnome.desktop.interface color-scheme")
  5. -- Check for 'light' anywhere in the output
  6. if result:match("light") then
  7. vim.o.background = "light"
  8. require('onedark').setup {
  9. style = 'light',
  10. transparent = false,
  11. term_colors = true,
  12. code_style = { comments = 'italic' },
  13. }
  14. require('onedark').load()
  15. -- Override GitSigns for light mode
  16. vim.api.nvim_set_hl(0, 'GitSignsAdd', { fg = '#2c7a36', bg = '#d9f2da' })
  17. vim.api.nvim_set_hl(0, 'GitSignsChange', { fg = '#a68a0d', bg = '#fbf0c9' })
  18. vim.api.nvim_set_hl(0, 'GitSignsDelete', { fg = '#a62621', bg = '#f9dada' })
  19. else
  20. vim.o.background = "dark"
  21. require('onedark').setup {
  22. style = 'cool',
  23. transparent = false,
  24. term_colors = true,
  25. code_style = { comments = 'italic' },
  26. }
  27. require('onedark').load()
  28. -- Override GitSigns for dark mode
  29. vim.api.nvim_set_hl(0, 'GitSignsAdd', { fg = '#98c379', bg = '#2e3f34' })
  30. vim.api.nvim_set_hl(0, 'GitSignsChange', { fg = '#e5c07b', bg = '#3e3d32' })
  31. vim.api.nvim_set_hl(0, 'GitSignsDelete', { fg = '#e06c75', bg = '#3f2e2e' })
  32. end
  33. -- Force colors for diagnostics and spell check underlines
  34. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineError', { undercurl = true, sp = '#ff0000' })
  35. vim.api.nvim_set_hl(0, 'DiagnosticUnderlineWarn', { undercurl = true, sp = '#ff8800' })
  36. vim.api.nvim_set_hl(0, 'SpellBad', { undercurl = true, sp = '#ffff00' })
  37. vim.api.nvim_set_hl(0, 'SpellCap', { undercurl = true, sp = '#ffff00' })
  38. vim.api.nvim_set_hl(0, 'SpellLocal', { undercurl = true, sp = '#ffff00' })
  39. vim.api.nvim_set_hl(0, 'SpellRare', { undercurl = true, sp = '#ffff00' })
  40. -- Force airline to refresh
  41. vim.g.airline_theme = 'onedark'
  42. if vim.fn.exists(':AirlineTheme') == 2 then
  43. vim.cmd('AirlineTheme onedark')
  44. end
  45. -- Force a full redraw to fix background issues in some terminals
  46. vim.cmd('redraw!')
  47. end
  48. -- Initial sync on load
  49. M.sync_theme()
  50. -- Set up signal handler for SIGUSR1 to trigger a theme sync
  51. local signal = vim.loop.new_signal()
  52. if signal then
  53. signal:start("sigusr1", function()
  54. vim.schedule(function()
  55. M.sync_theme()
  56. end)
  57. end)
  58. end
  59. return M