mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Allow running shell scripts from the FileManager/Favorites (#5804)
* Allow running Shell/Python scripts from the FM * Show an InfoMessage before/after running the script Since we're blocking the UI ;). * Allow running scripts from the favorites menu, too.
This commit is contained in:
@@ -661,6 +661,33 @@ function util.getFileNameSuffix(file)
|
||||
return suffix
|
||||
end
|
||||
|
||||
--- Returns true if the file is a script we allow running
|
||||
--- Basically a helper method to check a specific list of file extensions.
|
||||
---- @string filename
|
||||
---- @treturn boolean
|
||||
function util.isAllowedScript(file)
|
||||
local file_ext = string.lower(util.getFileNameSuffix(file))
|
||||
if file_ext == "sh"
|
||||
or file_ext == "py" then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
--- Companion helper function that returns the script's language,
|
||||
--- based on the filme extension.
|
||||
---- @string filename
|
||||
---- @treturn string (lowercase) (or nil if !isAllowedScript)
|
||||
function util.getScriptType(file)
|
||||
local file_ext = string.lower(util.getFileNameSuffix(file))
|
||||
if file_ext == "sh" then
|
||||
return "shell"
|
||||
elseif file_ext == "py" then
|
||||
return "python"
|
||||
end
|
||||
end
|
||||
|
||||
--- Gets human friendly size as string
|
||||
---- @int size (bytes)
|
||||
---- @bool right_align (by padding with spaces on the left)
|
||||
|
||||
Reference in New Issue
Block a user