Fix command detection in Hyprland Lua
This commit is contained in:
+22
-11
@@ -8,13 +8,34 @@ end
|
||||
|
||||
o.shell_quote = shell_quote
|
||||
|
||||
local function file_exists(path)
|
||||
local file = io.open(path, "r")
|
||||
if file then
|
||||
file:close()
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function o.shell_succeeds(command)
|
||||
local ok, _, code = os.execute(command .. " >/dev/null 2>&1")
|
||||
return ok == true or ok == 0 or code == 0
|
||||
end
|
||||
|
||||
function o.cmd_present(command)
|
||||
return o.shell_succeeds("command -v " .. shell_quote(command))
|
||||
if command:find("/", 1, true) then
|
||||
return file_exists(command)
|
||||
end
|
||||
|
||||
local path = os.getenv("PATH") or "/usr/local/bin:/usr/bin"
|
||||
for directory in (path .. ":"):gmatch("([^:]*):") do
|
||||
if file_exists((directory ~= "" and directory or ".") .. "/" .. command) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function o.cmd_missing(command)
|
||||
@@ -49,16 +70,6 @@ local function command_from(value, description)
|
||||
return value
|
||||
end
|
||||
|
||||
local function file_exists(path)
|
||||
local file = io.open(path, "r")
|
||||
if file then
|
||||
file:close()
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function o.preinstalled_bindings_enabled()
|
||||
if _G.omarchy_preinstalled_bindings ~= nil then
|
||||
return _G.omarchy_preinstalled_bindings == true
|
||||
|
||||
@@ -144,7 +144,18 @@ grep -Fq $'F9 Stop dictation (push-to-talk)' <<<"$voxtype_output" ||
|
||||
fail "installed Voxtype enables its release binding"
|
||||
pass "installed Voxtype conditionally enables dictation bindings"
|
||||
|
||||
missing_voxtype_output=$(run_omarchy_bindings "$voxtype_home")
|
||||
voxtype_without_execute_output=$(PATH="$voxtype_bin:$PATH" run_omarchy_bindings \
|
||||
"$voxtype_home" 'os.execute = function() return nil, "No child processes", 10 end')
|
||||
grep -Fq $'SUPER + CTRL + X Toggle dictation' <<<"$voxtype_without_execute_output" ||
|
||||
fail "Voxtype detection does not require spawning a subprocess"
|
||||
pass "installed Voxtype detection works without os.execute"
|
||||
|
||||
missing_bin="$tmpdir/missing-bin"
|
||||
mkdir -p "$missing_bin"
|
||||
ln -s "$(command -v lua)" "$missing_bin/lua"
|
||||
ln -s "$(command -v lspci)" "$missing_bin/lspci"
|
||||
ln -s "$(command -v sort)" "$missing_bin/sort"
|
||||
missing_voxtype_output=$(PATH="$missing_bin" run_omarchy_bindings "$voxtype_home")
|
||||
if grep -Fq $'SUPER + CTRL + X Toggle dictation' <<<"$missing_voxtype_output"; then
|
||||
fail "missing Voxtype skips its bindings"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user