This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

tools/nvim: implement cross-platform automatic theme switching

Replace vim-lumen with custom solution that automatically switches between
ayu (dark) and everforest (light) colorschemes based on system theme.

- macOS: uses defaults read -g AppleInterfaceStyle
- Linux: checks gsettings, kreadconfig5, and COLORFGBG
- Polls every 3 seconds for theme changes
- Provides :RefreshTheme command for manual switching

+78 -29
+78 -29
tools/nvim/flake-module.nix
··· 8 8 colorschemes = { 9 9 ayu = { 10 10 enable = true; 11 + settings = { 12 + mirage = false; 13 + dark = true; 14 + }; 11 15 settings.overrides = { 12 16 EoLSpace = { 13 17 bg = "#883333"; ··· 23 27 }; 24 28 }; 25 29 }; 30 + extraConfigLua = '' 31 + -- Cross-platform background detection and colorscheme switching 32 + local last_theme = nil 33 + 34 + local function detect_and_set_theme() 35 + local is_dark = false 36 + 37 + if vim.fn.has("mac") == 1 then 38 + -- macOS: check system appearance 39 + local result = vim.fn.system("defaults read -g AppleInterfaceStyle 2>/dev/null") 40 + is_dark = result:match("Dark") ~= nil 41 + elseif vim.fn.has("unix") == 1 then 42 + -- Linux: check if running under a dark theme 43 + -- Try multiple methods to detect dark theme 44 + local methods = { 45 + -- GNOME/GTK 46 + "gsettings get org.gnome.desktop.interface gtk-theme 2>/dev/null", 47 + "gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null", 48 + -- KDE 49 + "kreadconfig5 --file kdeglobals --group General --key ColorScheme 2>/dev/null", 50 + -- Check if COLORFGBG suggests dark background 51 + function() 52 + local colorfgbg = vim.env.COLORFGBG 53 + if colorfgbg then 54 + local fg, bg = colorfgbg:match("(%d+);(%d+)") 55 + if fg and bg then 56 + -- If foreground is lighter than background, likely dark theme 57 + return tonumber(fg) > tonumber(bg) 58 + end 59 + end 60 + return false 61 + end 62 + } 63 + 64 + for _, method in ipairs(methods) do 65 + if type(method) == "function" then 66 + is_dark = method() 67 + if is_dark then break end 68 + else 69 + local result = vim.fn.system(method) 70 + if result:match("[Dd]ark") or result:match("prefer%-dark") then 71 + is_dark = true 72 + break 73 + end 74 + end 75 + end 76 + end 77 + 78 + local new_theme = is_dark and "dark" or "light" 79 + 80 + if new_theme ~= last_theme then 81 + last_theme = new_theme 82 + vim.o.background = new_theme 83 + 84 + if is_dark then 85 + vim.cmd("colorscheme ayu") 86 + print("Switched to dark theme (ayu)") 87 + else 88 + vim.cmd("colorscheme everforest") 89 + print("Switched to light theme (everforest)") 90 + end 91 + end 92 + end 93 + 94 + -- Set initial theme 95 + vim.defer_fn(detect_and_set_theme, 100) 96 + 97 + -- Check for theme changes every 3 seconds (less frequent to be less resource intensive) 98 + local timer = vim.loop.new_timer() 99 + timer:start(3000, 3000, vim.schedule_wrap(detect_and_set_theme)) 100 + 101 + -- Create a command to manually refresh theme 102 + vim.api.nvim_create_user_command("RefreshTheme", detect_and_set_theme, {}) 103 + ''; 26 104 globals = { 27 105 mapleader = " "; 28 - lumen_light_colorscheme = "everforest"; 29 - lumen_dark_colorscheme = "ayu"; 30 106 }; 31 107 opts = { 32 108 mouse = "a"; ··· 51 127 " need to use lua to expand $HOME 52 128 lua vim.o.undodir = vim.fs.normalize('$HOME/.vim/undodir') 53 129 ''; 54 - extraPackages = [ 55 - pkgs.glib # for vim-lumen 56 - ]; 57 130 extraPlugins = [ 58 131 pkgs.vimPlugins.vim-fetch 59 - (pkgs.vimUtils.buildVimPlugin { 60 - name = "vim-lumen"; 61 - src = pkgs.fetchFromGitHub { 62 - owner = "vimpostor"; 63 - repo = "vim-lumen"; 64 - rev = "ac13c32c3e309f6c6a84ff6cad8dbb135e75f0e4"; 65 - hash = "sha256-rsDUDI9lh4CEX1upMBjeyBOm99GAXWGPQ9vSCN8cmFo="; 66 - }; 67 - }) 68 132 ]; 69 - # not ready yet, we are waiting for none-ls to get updated 70 - # extraConfigLua = '' 71 - # local null_ls = require("null-ls") 72 - # null_ls.register(null_ls.builtins.formatting.nix_flake_fmt) 73 - # ''; 74 133 keymaps = [ 75 134 { 76 135 mode = "i"; ··· 91 150 mode = "n"; 92 151 key = "<Space>"; 93 152 action = "<Nop>"; 94 - } 95 - { 96 - mode = "n"; 97 - key = "<leader>sd"; 98 - action = ":colorscheme ayu-dark<cr>"; 99 - } 100 - { 101 - mode = "n"; 102 - key = "<leader>sw"; 103 - action = ":colorscheme ayu-light<cr>"; 104 153 } 105 154 { 106 155 mode = [