Created
September 20, 2010 13:07
-
-
Save thinca/587866 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function keys(t) | |
local keylist = {} | |
for k in pairs(t) do | |
table.insert(keylist, k) | |
end | |
local i = 0 | |
return function() | |
i = i + 1 | |
return keylist[i] | |
end | |
end | |
function addext(exts, mid) | |
mid = mid or '' | |
return function(cmd) | |
if cmd:match('%.') then | |
return false | |
end | |
local variation={} | |
local cmdl=cmd:lower() | |
for ext, _ in exts do | |
variation[ cmdl .. mid .. ext:lower() ] = true | |
end | |
local path='.;' .. os.getenv('PATH') | |
for path1 in path:gmatch('[^;]+') do | |
for fname in nyaos.dir(path1) do | |
if variation[ fname:lower() ] then | |
return fname | |
end | |
end | |
end | |
end | |
end | |
function nyaos.filter2.ext(cmdline) | |
return cmdline:gsub('^%S+', addext(os.getenv('PATHEXT'):gmatch('[^;]+'))) | |
end | |
function nyaos.filter.ext(cmdline) | |
return cmdline:gsub('^%S+', addext(keys(nyaos.suffix), '.')) | |
end | |
function nyaos.filter.luacode(cmdline) | |
return cmdline:gsub('%%(%b())', function(m) | |
local status, result = pcall( loadstring('return '..m) ) | |
if status then | |
return result | |
end | |
print('Ignore invalid Lua expression: '..m) | |
end) | |
end | |
function nyaos.filter.command(cmdline) | |
return cmdline:gsub('$(%b())', function(m) | |
return nyaos.eval(m:sub(2,-2)) | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment