moved path info to os env stuff; fixed a *really* stupid bug in path resolving in the shell

This commit is contained in:
Florian Nücke 2014-02-17 02:43:38 +01:00
parent 183f00b398
commit d6d0cf2092
2 changed files with 9 additions and 15 deletions

View File

@ -4,7 +4,7 @@ local fs = require("filesystem")
local shell = require("shell")
local unicode = require("unicode")
local env = {}
local env = {PATH="/bin:/usr/bin:/home/bin"}
os.execute = function(command)
if not command then

View File

@ -5,7 +5,6 @@ local text = require("text")
local shell = {}
local cwd = "/"
local path = {"/bin/", "/usr/bin/", "/home/bin/"}
local aliases = {}
local running = setmetatable({}, {__mode="k"})
local isLoading = false
@ -33,13 +32,16 @@ local function findFile(name, ext)
files[file] = true
end
if ext and unicode.sub(name, -(1 + unicode.len(ext))) == "." .. ext then
-- Name already contains extension, prioritize.
if files[name] then
return true, fs.concat(dir, name)
end
elseif files[name] then
-- Check exact name.
return true, fs.concat(dir, name)
elseif ext then
name = name .. "." .. ext
-- Check name with automatially added extension.
local name = name .. "." .. ext
if files[name] then
return true, fs.concat(dir, name)
end
@ -53,8 +55,8 @@ local function findFile(name, ext)
else
local found, where = findIn(shell.getWorkingDirectory())
if found then return where end
for _, p in ipairs(path) do
local found, where = findIn(p)
for path in string.gmatch(shell.getPath(), "[^:]+") do
local found, where = findIn(path)
if found then return where end
end
end
@ -332,19 +334,11 @@ function shell.setWorkingDirectory(dir)
end
function shell.getPath()
return table.concat(path, ":")
return os.getenv("PATH")
end
function shell.setPath(value)
checkArg(1, value, "string")
path = {}
for p in string.gmatch(value, "[^:]+") do
p = fs.canonical(text.trim(p))
if unicode.sub(p, 1, 1) ~= "/" then
p = "/" .. p
end
table.insert(path, p)
end
os.setenv("PATH", value)
end
function shell.resolve(path, ext)