aboutsummaryrefslogtreecommitdiff
path: root/helpers.lua
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@higgsboson.tk>2014-11-12 23:43:24 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2014-11-15 22:03:12 +0100
commit336ce9bbd7c620226d0ef01ba58c02be12f7b90e (patch)
tree5b0a621678799fcbb68add662b937087354989eb /helpers.lua
parent50fd2334b6a720f798782f7690287b71642cb9a8 (diff)
downloadvicious-legacy-336ce9bbd7c620226d0ef01ba58c02be12f7b90e.tar.xz
shell escape variables before passing them to the shell
Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
Diffstat (limited to 'helpers.lua')
-rw-r--r--helpers.lua9
1 files changed, 9 insertions, 0 deletions
diff --git a/helpers.lua b/helpers.lua
index 4c15690..7c8dd0c 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -97,6 +97,15 @@ function helpers.escape(text)
end
-- }}}
+-- {{{ Escape a string for save usage on the command line
+function helpers.shellquote(s)
+ if s == nil then return "" end
+ -- use single quotes, and put single quotes into double quotes
+ -- the string $'b is then quoted as '$'"'"'b'"'"'
+ return "'" .. s:gsub("'", "'\"'\"'") .. "'"
+end
+-- }}}
+
-- {{{ Capitalize a string
function helpers.capitalize(text)
return text and text:gsub("([%w])([%w]*)", function(c, s)