Files
LeonOS/data/computercraft/lua/rom/programs/shell.lua
Leonmmcoset acad8982aa feat(list): 增强列表命令功能并改进显示格式
- 添加 `-l` 参数支持显示文件详细信息
- 改进文件列表的排序和分类显示
- 为不同文件类型添加颜色标识
- 添加统计信息和提示文本
- 修复重启命令别名从 "restart" 改为 "reboot"
- 更新系统版本号显示为 LeonOS 1.0
2025-08-31 17:52:37 +08:00

81 lines
1.8 KiB
Lua

-- rc.shell
local rc = require("rc")
local fs = require("fs")
local term = require("term")
local shell = require("shell")
local colors = require("colors")
local thread = require("rc.thread")
local textutils = require("textutils")
if os.version then
textutils.coloredPrint(colors.yellow, os.version(), colors.white)
else
textutils.coloredPrint(colors.yellow, rc.version(), colors.white)
end
thread.vars().parentShell = thread.id()
shell.init(_ENV)
if not shell.__has_run_startup then
shell.__has_run_startup = true
if fs.exists("/startup.lua") then
local ok, err = pcall(dofile, "/startup.lua")
if not ok and err then
io.stderr:write(err, "\n")
end
end
if fs.exists("/startup") and fs.isDir("/startup") then
local files = fs.list("/startup/")
table.sort(files)
for f=1, #files, 1 do
local ok, err = pcall(dofile, "/startup/"..files[f])
if not ok and err then
io.stderr:write(err, "\n")
end
end
end
end
local aliases = {
background = "bg",
clr = "clear",
cp = "copy",
dir = "list",
foreground = "fg",
mv = "move",
rm = "delete",
rs = "redstone",
sh = "shell",
ps = "threads",
restart = "reboot"
}
for k, v in pairs(aliases) do
shell.setAlias(k, v)
end
local completions = "/rc/completions"
for _, prog in ipairs(fs.list(completions)) do
dofile(fs.combine(completions, prog))
end
local history = {}
while true do
term.setTextColor(colors.yellow)
term.setBackgroundColor(colors.black)
rc.write(textutils.coloredPrint(colors.yellow, "$"..shell.dir(), colors.green, " >>> "))
term.setTextColor(colors.white)
local text = term.read(nil, history, shell.complete)
if #text > 0 then
history[#history+1] = text
local ok, err = shell.run(text)
if not ok and err then
io.stderr:write(err, "\n")
end
end
end