Skip to content

Commit

Permalink
fix: vim.fn booleans & format error strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nekowinston committed Oct 10, 2024
1 parent 3022174 commit ae290ca
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions lua/auto-dark-mode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ M.init = function()
if M.state.system == "Darwin" then
M.state.query_command = { "defaults", "read", "-g", "AppleInterfaceStyle" }
elseif M.state.system == "Linux" then
if not vim.fn.executable("dbus-send") then
error([[
auto-dark-mode.nvim:
`dbus-send` is not available. The Linux implementation of
auto-dark-mode.nvim relies on `dbus-send` being on the `$PATH`.
]])
if vim.fn.executable("dbus-send") == 0 then
error(
"auto-dark-mode.nvim: `dbus-send` is not available. The Linux implementation of auto-dark-mode.nvim relies on `dbus-send` being on the `$PATH`."
)
end

M.state.query_command = {
Expand All @@ -92,18 +90,16 @@ M.init = function()
-- on WSL, if `reg.exe` cannot be found on the `$PATH`
-- (see interop.appendWindowsPath https://learn.microsoft.com/en-us/windows/wsl/wsl-config),
-- assume that it's in the default location
if M.state.system == "WSL" and not vim.fn.executable("reg.exe") then
if M.state.system == "WSL" and vim.fn.executable("reg.exe") == 0 then
local assumed_path = "/mnt/c/Windows/system32/reg.exe"

if vim.fn.filereadable(assumed_path) then
if vim.fn.filereadable(assumed_path) == 1 then
reg = assumed_path
else
-- `reg.exe` isn't on `$PATH` or in the default location, so throw an error
error([[
auto-dark-mode.nvim:
`reg.exe` is not available. To support syncing with the host system,
this plugin relies on `reg.exe` being on the `$PATH`.
]])
error(
"auto-dark-mode.nvim: `reg.exe` is not available. To support syncing with the host system, this plugin relies on `reg.exe` being on the `$PATH`."
)
end
end

Expand All @@ -130,11 +126,9 @@ M.init = function()
end
M.state.query_command = extra_args
else
error([[
auto-dark-mode.nvim:
Running as `root`, but `$SUDO_USER` is not set.
Please open an issue to add support for your system.
]])
error(
"auto-dark-mode.nvim: Running as `root`, but `$SUDO_USER` is not set. Please open an issue to add support for your system."
)
end
end

Expand Down

0 comments on commit ae290ca

Please sign in to comment.