repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: fix wsl constant

30546269b65235ce41e1569e76467f10d0a2c3a2

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (2)

+36 / −32 text lines

Diff layout

neovim/lua/bugabinga/options/keymaps.lua

Modified

+1 / −1 text lines

6060 if file_under_cursor and file_under_cursor:match '%a+://.+' then
6161 vim.system(
6262 ---@diagnostic disable-next-line: assign-type-mismatch
63 (const.win32 or const.wsl2) and { 'cmd.exe', '/C', 'start', 'msedge', file_under_cursor }
63 (const.win32 or const.wsl) and { 'cmd.exe', '/C', 'start', 'msedge', file_under_cursor }
6464 or { 'firefox', file_under_cursor },
6565 { text = true },
6666 function ( completed )

neovim/lua/std/const.lua

Modified

+35 / −31 text lines

1return {
2 win32 = vim.loop.os_uname().sysname:match 'Win',
3 wsl2 = vim.loop.os_uname().release:match 'WSL2',
4 os_background = (function ()
5 -- Default value
6 local background = 'light'
7 local uname = vim.uv.os_uname()
8 -- First check whether we are on WSL or Windows
9 if vim.loop.os_uname().release:match 'WSL2' then
10 -- Check if 'reg.exe' is executable
11 if vim.fn.executable 'reg.exe' ~= 0 then
12 -- Execute command to check if the win32 appearance is set to Dark
13 local appsUseLightTheme = vim.fn.system { 'reg.exe', 'Query',
14 'HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize', '/v', 'AppsUseLightTheme' }
15 if not appsUseLightTheme:find '0x1' then
16 background = 'dark'
17 end
18 end
19 -- Check if 'busctl' is executable (part of systemd)
20 elseif vim.fn.executable 'busctl' ~= 0 then
21 -- Get the current color scheme from xdg-desktop-portal using busctl
22 local result = vim.fn.system {
23 'busctl', '--user', 'call', 'org.freedesktop.portal.Desktop', '/org/freedesktop/portal/desktop',
24 'org.freedesktop.portal.Settings', 'ReadOne', 'ss', 'org.freedesktop.appearance', 'color-scheme',
25 }
26 -- The result is in the form of "v u 0" for light and "v u 1" for dark
27 local color_scheme = result:match 'u%s+(%d+)'
1local uname = vim.uv.os_uname()
2local win32 = vim.uv.os_uname().sysname:match 'Win' and true or false
3local wsl = vim.uv.os_uname().release:match 'WSL2' and true or false
29 if color_scheme == '1' then
5local os_background = function ()
6 -- Default value
7 local background = 'light'
8 -- First check whether we are on WSL or Windows
9 if win32 or wsl then
10 -- Check if 'reg.exe' is executable
11 if vim.fn.executable 'reg.exe' ~= 0 then
12 -- Execute command to check if the win32 appearance is set to Dark
13 local appsUseLightTheme = vim.fn.system { 'reg.exe', 'Query',
14 'HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize', '/v', 'AppsUseLightTheme' }
15 if not appsUseLightTheme:find '0x1' then
3016 background = 'dark'
3117 end
32 else
3318 end
19 -- Check if 'busctl' is executable (part of systemd)
20 elseif vim.fn.executable 'busctl' ~= 0 then
21 -- Get the current color scheme from xdg-desktop-portal using busctl
22 local result = vim.fn.system {
23 'busctl', '--user', 'call', 'org.freedesktop.portal.Desktop', '/org/freedesktop/portal/desktop',
24 'org.freedesktop.portal.Settings', 'ReadOne', 'ss', 'org.freedesktop.appearance', 'color-scheme',
25 }
26 -- The result is in the form of "v u 0" for light and "v u 1" for dark
27 local color_scheme = result:match 'u%s+(%d+)'
35 return background
36 end)(),
29 if color_scheme == '1' then
30 background = 'dark'
31 end
32 end
34 return background
35end
37return {
38 uname = uname,
39 win32 = win32,
40 wsl = wsl,
41 os_background = os_background(),