Fixes for behaviour of os.execute in lua versions >5.1

This commit is contained in:
Yessiest 2021-11-18 02:32:34 +04:00
parent bd604e4f91
commit ca613ba0ed
3 changed files with 23 additions and 4 deletions

Binary file not shown.

View File

@ -1,17 +1,26 @@
-- A small utility function to generate thumbnails for images -- A small utility function to generate thumbnails for images
local spawn = require("awful.spawn") local spawn = require("awful.spawn")
local thumbnailer = {} local thumbnailer = {}
-- annoying shit but that's what happens
if _VERSION ~= "Lua 5.1" then
execute = function(comm)
return select(3,os.execute(comm))
end
else
execute = os.execute
end
thumbnailer.generate = function(path,thumb_path,height) thumbnailer.generate = function(path,thumb_path,height)
assert(type(path) == "string", "argumenr #1 (path) is not a string") assert(type(path) == "string", "argumenr #1 (path) is not a string")
assert(type(thumb_path) == "string", "argument #2 (thumbnail path) is not a string") assert(type(thumb_path) == "string", "argument #2 (thumbnail path) is not a string")
assert(type(height) == "number","argument #3 (height) is not a number") assert(type(height) == "number","argument #3 (height) is not a number")
if os.execute("ls "..path) ~= 0 then require("naughty").notify({text = tostring(path).." "..tostring(thumb_path.." ")..tostring(height)})
if execute("ls "..path) ~= 0 then
return false, "unable to access image directory" return false, "unable to access image directory"
end end
if os.execute("ls "..thumb_path) == 0 then if execute("ls "..thumb_path) == 0 then
return true return true
end end
if os.execute("mkdir "..thumb_path) ~= 0 then if execute("mkdir "..thumb_path) ~= 0 then
return false, "unable to create thumbnail directory" return false, "unable to create thumbnail directory"
end end
spawn("mogrify -thumbnail x"..tostring(height).." -path '"..thumb_path.."' '"..path.."'/*.{jpg,png}") spawn("mogrify -thumbnail x"..tostring(height).." -path '"..thumb_path.."' '"..path.."'/*.{jpg,png}")

View File

@ -3,6 +3,16 @@
-- It's like cron's @reboot but with additional awesomewm specific features -- It's like cron's @reboot but with additional awesomewm specific features
local awful = require("awful") local awful = require("awful")
local rcfile = io.open(global.config_dir.."rc.lua") local rcfile = io.open(global.config_dir.."rc.lua")
local execute
-- why thank you lua changes, i appreciate this shit.
-- (luajit is deprecated my ASS, find me a faster version then)
if _VERSION ~= "Lua 5.1" then
execute = function(comm)
return select(3,os.execute(comm))
end
else
execute = os.execute
end
local execd = {} local execd = {}
-- load persistent file for "o" tag -- load persistent file for "o" tag
local execd_file = io.open("/tmp/awesomerc.started","r") local execd_file = io.open("/tmp/awesomerc.started","r")
@ -25,7 +35,7 @@ local function check_pid(prg)
break break
end end
end end
if os.execute("pgrep "..prgname) == 0 then if execute("pgrep "..prgname) == 0 then
return true return true
else else
return false return false