Skip to content

Commit

Permalink
Tuesday 2024-11-26 19:24:40
Browse files Browse the repository at this point in the history
  • Loading branch information
jackokring committed Nov 26, 2024
1 parent 91c8c6c commit 9a5edfe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lua/doris/audio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ end
---@param what string
_G.say = function(what)
if espeak then
os.execute('espeak-ng "' .. what .. '"&')
-- someone's going to do something with quotes for speech
-- and perhaps $VAR, so get an escaped quoted string
os.execute("espeak-ng " .. os.shell_quote(what) .. "&")
end
end

Expand Down
18 changes: 17 additions & 1 deletion lua/doris/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,27 @@ _G.bin_root = function()
return script_path() .. ".." .. path_separator() .. ".." .. path_separator()
end

-- os utilities not _G ones
local nv = require("doris.novaride")
nv.track(os)

---replace double quotes by escaped double quotes only
---thn escape $ and add surrounding double quotes
---@param chars string
---@return string
os.shell_quote = function(chars)
-- and then there's $ as in os $HOME etc.
local q = string.gsub(chars, "[^\\]%$", "\\$")
return '"' .. string.gsub(string.gsub(q, "\\", "\\\\"), '"', '\\"') .. '"'
end

---check if a command exists
---@param cmd string
---@return boolean
_G.os.has = function(cmd)
os.has = function(cmd)
return os.execute("which " .. cmd) == 0
end

nv.untrack(os)

novaride.restore()

0 comments on commit 9a5edfe

Please sign in to comment.