Made Histrory Length a EnvVar

Well, there is it!
This commit is contained in:
Wuerfel_21 2014-06-17 09:46:41 +02:00
parent fe08db56cc
commit 8ca7306f34
2 changed files with 10 additions and 1 deletions

View File

@ -7,6 +7,14 @@ local shell = require("shell")
local term = require("term") local term = require("term")
local text = require("text") local text = require("text")
local function getHistSize()
if os.getenv("HISTSIZE") then
return os.getenv("HISTSIZE")
else
return 10
end
end
local function expand(value) local function expand(value)
local result = value:gsub("%$(%w+)", os.getenv):gsub("%$%b{}", local result = value:gsub("%$(%w+)", os.getenv):gsub("%$%b{}",
function(match) return os.getenv(expand(match:sub(3, -2))) or match end) function(match) return os.getenv(expand(match:sub(3, -2))) or match end)
@ -165,7 +173,7 @@ if #args == 0 and (io.input() == io.stdin or options.i) and not options.c then
term.write("exit\n") term.write("exit\n")
return -- eof return -- eof
end end
while #history > 20 do while #history > getHistSize() do
table.remove(history, 1) table.remove(history, 1)
end end
command = text.trim(command) command = text.trim(command)

View File

@ -16,6 +16,7 @@ local env = {
SHELL="/bin/sh", SHELL="/bin/sh",
TMP="/tmp", -- Depricated TMP="/tmp", -- Depricated
TMPDIR="/tmp" TMPDIR="/tmp"
HISTSIZE=10
} }
os.execute = function(command) os.execute = function(command)