v0.8.0 - Added help and fetch.
This commit is contained in:
+4
-1
@@ -2,7 +2,10 @@ local args = {...}
|
|||||||
local file = args[1]
|
local file = args[1]
|
||||||
args = nil
|
args = nil
|
||||||
local fs = import("filesystem")
|
local fs = import("filesystem")
|
||||||
|
if not file then
|
||||||
|
shell.run("help cat")
|
||||||
|
return
|
||||||
|
end
|
||||||
if file:sub(1, 1) ~= "/" then
|
if file:sub(1, 1) ~= "/" then
|
||||||
file = shell.workingDirectory .. file
|
file = shell.workingDirectory .. file
|
||||||
end
|
end
|
||||||
|
|||||||
+4
-5
@@ -11,15 +11,14 @@ if toFile:sub(1, 1) ~= "/" then
|
|||||||
end
|
end
|
||||||
if fromFile == toFile then
|
if fromFile == toFile then
|
||||||
print("\27[91mSource and destination are the same.")
|
print("\27[91mSource and destination are the same.")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
if not fs.exists(fromFile) then
|
if not fs.exists(fromFile) then
|
||||||
print("\27[91mSource file does not exist.")
|
print("\27[91mSource file does not exist.")
|
||||||
end
|
|
||||||
if fs.exists(toFile) then
|
|
||||||
print("Destination file already exists. Overwrite it? [Y/n] ", false)
|
|
||||||
if read():lower() == "n" then
|
|
||||||
print("Aborted.")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if fs.exists(toFile) and not (table.find(args, "-o") or table.find(args, "--overwrite")) then
|
||||||
|
print("\27[91mDestination file already exists. Run this command again with -o to overwrite it.")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
fs.copy(fromFile, toFile)
|
fs.copy(fromFile, toFile)
|
||||||
|
|||||||
+68
-1
@@ -1 +1,68 @@
|
|||||||
print("\27[40m \27[41m \27[42m \27[43m \27[44m \27[45m \27[46m \27[47m \n\27[100m \27[101m \27[102m \27[103m \27[104m \27[105m \27[106m \27[107m ")
|
termlib.cursorPosY = termlib.cursorPosY + 2
|
||||||
|
print(" \27[93m┌┬┐ ┌┐ ┌┐ \n ││├─┤├┬┬┘├─┐\n │┐├┘││││││││\n ││││││││││┌┤\n └┴┴─┴┼┐├─┴─┘\n └─┘ ")
|
||||||
|
termlib.cursorPosX, termlib.cursorPosY = 17, termlib.cursorPosY - 8
|
||||||
|
print("\27[92mOS\27[0m: ".._OSVERSION)
|
||||||
|
termlib.cursorPosX = 17
|
||||||
|
print("\27[92mArchitecture\27[0m: ".._VERSION)
|
||||||
|
termlib.cursorPosX = 17
|
||||||
|
local componentCounter = 0
|
||||||
|
for _, _ in component.list() do
|
||||||
|
componentCounter = componentCounter + 1
|
||||||
|
end
|
||||||
|
print("\27[92mComponents\27[0m: "..tostring(componentCounter))
|
||||||
|
termlib.cursorPosX = 17
|
||||||
|
print("\27[92mCoroutines\27[0m: "..tostring(#cormgr.corList))
|
||||||
|
termlib.cursorPosX = 17
|
||||||
|
print("\27[92mBattery\27[0m: "..tostring(math.floor(computer.maxEnergy() / computer.energy() * 1000 + 0.5) / 10).."%")
|
||||||
|
termlib.cursorPosX = 17
|
||||||
|
local totalMemory = computer.totalMemory()
|
||||||
|
local usedMemory = computer.totalMemory() - computer.freeMemory()
|
||||||
|
local totalMemoryString
|
||||||
|
if convert(totalMemory, "B", "GiB") >= 1 then
|
||||||
|
totalMemoryString = tostring(math.floor(convert(totalMemory, "B", "GiB") * 100 + 0.5) / 100) .. " GiB"
|
||||||
|
elseif convert(totalMemory, "B", "MiB") >= 1 then
|
||||||
|
totalMemoryString = tostring(math.floor(convert(totalMemory, "B", "MiB") * 100 + 0.5) / 100) .. " MiB"
|
||||||
|
elseif convert(totalMemory, "B", "KiB") >= 1 then
|
||||||
|
totalMemoryString = tostring(math.floor(convert(totalMemory, "B", "KiB") * 100 + 0.5) / 100) .. " KiB"
|
||||||
|
else
|
||||||
|
totalMemoryString = tostring(totalMemory) .. " B"
|
||||||
|
end
|
||||||
|
local usedMemoryString
|
||||||
|
if convert(usedMemory, "B", "GiB") >= 1 then
|
||||||
|
usedMemoryString = tostring(math.floor(convert(usedMemory, "B", "GiB") * 100 + 0.5) / 100) .. " GiB"
|
||||||
|
elseif convert(usedMemory, "B", "MiB") >= 1 then
|
||||||
|
usedMemoryString = tostring(math.floor(convert(usedMemory, "B", "MiB") * 100 + 0.5) / 100) .. " MiB"
|
||||||
|
elseif convert(usedMemory, "B", "KiB") >= 1 then
|
||||||
|
usedMemoryString = tostring(math.floor(convert(usedMemory, "B", "KiB") * 100 + 0.5) / 100) .. " KiB"
|
||||||
|
else
|
||||||
|
usedMemoryString = tostring(usedMemory) .. " B"
|
||||||
|
end
|
||||||
|
print("\27[92mMemory\27[0m: "..usedMemoryString.." / "..totalMemoryString)
|
||||||
|
termlib.cursorPosX = 17
|
||||||
|
local totalDisk = component.invoke(computer.getBootAddress(), "spaceTotal")
|
||||||
|
local usedDisk = component.invoke(computer.getBootAddress(), "spaceUsed")
|
||||||
|
local totalDiskString
|
||||||
|
if convert(totalDisk, "B", "GiB") >= 1 then
|
||||||
|
totalDiskString = tostring(math.floor(convert(totalDisk, "B", "GiB") * 100 + 0.5) / 100) .. " GiB"
|
||||||
|
elseif convert(totalDisk, "B", "MiB") >= 1 then
|
||||||
|
totalDiskString = tostring(math.floor(convert(totalDisk, "B", "MiB") * 100 + 0.5) / 100) .. " MiB"
|
||||||
|
elseif convert(totalDisk, "B", "KiB") >= 1 then
|
||||||
|
totalDiskString = tostring(math.floor(convert(totalDisk, "B", "KiB") * 100 + 0.5) / 100) .. " KiB"
|
||||||
|
else
|
||||||
|
totalDiskString = tostring(totalDisk) .. " B"
|
||||||
|
end
|
||||||
|
local usedDiskString
|
||||||
|
if convert(usedDisk, "B", "GiB") >= 1 then
|
||||||
|
usedDiskString = tostring(math.floor(convert(usedDisk, "B", "GiB") * 100 + 0.5) / 100) .. " GiB"
|
||||||
|
elseif convert(usedDisk, "B", "MiB") >= 1 then
|
||||||
|
usedDiskString = tostring(math.floor(convert(usedDisk, "B", "MiB") * 100 + 0.5) / 100) .. " MiB"
|
||||||
|
elseif convert(usedDisk, "B", "KiB") >= 1 then
|
||||||
|
usedDiskString = tostring(math.floor(convert(usedDisk, "B", "KiB") * 100 + 0.5) / 100) .. " KiB"
|
||||||
|
else
|
||||||
|
usedDiskString = tostring(usedDisk) .. " B"
|
||||||
|
end
|
||||||
|
print("\27[92mDisk\27[0m: "..usedDiskString.." / "..totalDiskString.."\n")
|
||||||
|
termlib.cursorPosX = 17
|
||||||
|
print("\27[40m \27[41m \27[42m \27[43m \27[44m \27[45m \27[46m \27[47m ")
|
||||||
|
termlib.cursorPosX = 17
|
||||||
|
print("\27[100m \27[101m \27[102m \27[103m \27[104m \27[105m \27[106m \27[107m ")
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
local fs = import("filesystem")
|
||||||
|
local args = {...}
|
||||||
|
local command = args[1]
|
||||||
|
args = nil
|
||||||
|
if not command then
|
||||||
|
local handle, data, tmpdata = fs.open("/halyde/apps/helpdb/default.txt", "r"), "", nil
|
||||||
|
repeat
|
||||||
|
tmpdata = handle:read(math.huge or math.maxinteger)
|
||||||
|
data = data .. (tmpdata or "")
|
||||||
|
until not tmpdata
|
||||||
|
print(data)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if shell.aliases[command] then
|
||||||
|
command = shell.aliases[command]
|
||||||
|
end
|
||||||
|
if fs.exists("/halyde/apps/helpdb/" .. command .. ".txt") then
|
||||||
|
local handle, data, tmpdata = fs.open("/halyde/apps/helpdb/" .. command .. ".txt", "r"), "", nil
|
||||||
|
repeat
|
||||||
|
tmpdata = handle:read(math.huge or math.maxinteger)
|
||||||
|
data = data .. (tmpdata or "")
|
||||||
|
until not tmpdata
|
||||||
|
print(data)
|
||||||
|
else
|
||||||
|
print("Could not find help file for: " .. command .. ".")
|
||||||
|
end
|
||||||
@@ -1 +1,8 @@
|
|||||||
|
Usage: cat [FILE]
|
||||||
|
Concatenates and prints a file.
|
||||||
|
|
||||||
|
FILE Specifies the path to the file to print.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
cat /init.lua Concatenates and prints init.lua in the root directory.
|
||||||
|
cat help.lua Concatenates and prints help.lua in the current working directory.
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
Usage: cd [PATH]
|
||||||
|
Sets the shell working directory.
|
||||||
|
|
||||||
|
PATH Specifies the path to set the shell working directory to.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
cd /home/ Sets the shell working directory to /home/.
|
||||||
|
cd halyde Sets the shell working directory to a directory named "halyde" in the current working directory.
|
||||||
|
cd .. Sets the shell working directory back one directory.
|
||||||
|
.. Equivalent of "cd ..".
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Usage: clear
|
||||||
|
Clears the screen.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
clear Clears the screen.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
Usage: cp [FLAGS] [SOURCE] [DESTINATION]
|
||||||
|
Copies a file.
|
||||||
|
|
||||||
|
-o, --overwrite Allows any file that might be at the destination to be overwritten.
|
||||||
|
SOURCE Specifies the file to be copied.
|
||||||
|
DESTINATION Specifies the path to copy the file to.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
cp /home/a.txt /b.txt Copies the file at /home/a.txt to /b.txt.
|
||||||
|
cp -o c.lua d.txt Copies the file c.lua to another file called d.txt in the shell working directory, overwriting any file that might be there.
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
All current Halyde shell commands:
|
||||||
|
cat Concatenates and prints a file.
|
||||||
|
cd Changes directory.
|
||||||
|
clear Clears the screen.
|
||||||
|
cp Copies a file.
|
||||||
|
echo Prints a message.
|
||||||
|
fetch Displays system information.
|
||||||
|
help Shows this.
|
||||||
|
ls Lists files.
|
||||||
|
lua Starts the Lua shell.
|
||||||
|
mv Moves/renames a file.
|
||||||
|
rm Deletes a file.
|
||||||
|
|
||||||
|
You can get additional information on any app or command by running:
|
||||||
|
help [COMMAND]
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
Usage: echo [TEXT]...
|
||||||
|
Concatenates and prints text to the terminal.
|
||||||
|
|
||||||
|
TEXT Text to print.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
echo test Prints "test" to the terminal.
|
||||||
|
echo Hello World! Prints "Hello World!" to the terminal.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Usage: fetch
|
||||||
|
Displays system information including OS version, Lua version, memory, etc.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
fetch Displays system information.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
Usage: help [COMMAND]
|
||||||
|
Displays info on the command specified, or a list of commands if one is not specified.
|
||||||
|
|
||||||
|
COMMAND Command to display information on.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
help Displays a list of all default commands available.
|
||||||
|
help cp Displays information about the cp command.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
Usage: ls [PATH]
|
||||||
|
Lists all files and directories in the specified path, or in the shell working directory if the path isn't specified.
|
||||||
|
Directories are shown in [93myellow[0m, executable files are shown in [92mgreen[0m, and other files are shown in white.
|
||||||
|
|
||||||
|
PATH Path to the folder to list files and directories from.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
ls Lists all files and directories from the current shell working directory.
|
||||||
|
ls /halyde Lists all files and directories from /halyde.
|
||||||
|
ls apps Lists all files and directories from the apps directory in the shell working directory.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Usage: lua
|
||||||
|
Starts the Lua shell, where you can type commands to interpret them in real time.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
lua Starts the Lua shell.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
Usage: mv [FLAGS] [SOURCE] [DESTINATION]
|
||||||
|
Moves/renames a file.
|
||||||
|
|
||||||
|
-o, --overwrite Allows any file that might be at the destination to be overwritten.
|
||||||
|
SOURCE Specifies the file to be moved/renamed.
|
||||||
|
DESTINATION Specifies the path/filename to move/rename the file to.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
mv /home/a.txt /b.txt Moves the file at /home/a.txt to /b.txt.
|
||||||
|
mv -o c.lua d.txt Renames the file c.lua to another file called d.txt in the shell working directory, overwriting any file that might be there.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
Usage: rm [FLAGS] [PATH]
|
||||||
|
Removes files and directories.
|
||||||
|
|
||||||
|
-r, --recursive Removes directories and their contents recursively.
|
||||||
|
-f, --force Ignores nonexistent files or directories.
|
||||||
|
PATH Specifies the file to be moved/renamed.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
rm a.txt Removes a.txt in the current shell working directory.
|
||||||
|
rm -r -f /halyde/core/ Removes everything in /halyde/core forcedly and recursively. Note that trying this on a real machine will remove critical Halyde system files and cause it to stop working.
|
||||||
+2
-5
@@ -15,11 +15,8 @@ end
|
|||||||
if not fs.exists(fromFile) then
|
if not fs.exists(fromFile) then
|
||||||
print("\27[91mSource file does not exist.")
|
print("\27[91mSource file does not exist.")
|
||||||
end
|
end
|
||||||
if fs.exists(toFile) then
|
if fs.exists(toFile) and not (table.find(args, "-o") or table.find(args, "--overwrite")) then
|
||||||
print("Destination file already exists. Overwrite it? [Y/n] ", false)
|
print("\27[91mDestination file already exists. Run this command again with -o to overwrite it.")
|
||||||
if read():lower() == "n" then
|
|
||||||
print("Aborted.")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
|
||||||
fs.rename(fromFile, toFile)
|
fs.rename(fromFile, toFile)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local shellcfg = {
|
local shellcfg = {
|
||||||
["startupMessage"] = "\n │\n │ ".._OSVERSION.." running on ".._VERSION..'\n │ Welcome! Type "help" to get started.\n │\n ', -- message shown on startup
|
["startupMessage"] = "\n │\n │ ".._OSVERSION..'\n │ Welcome! Type "help" to get started.\n │\n ', -- message shown on startup
|
||||||
["prompt"] = "\x1b[92m%s > \x1b[0m", -- shell prompt, %s will be replaced with working directory. example: "%s > " turns to "/current/working/directory > "
|
["prompt"] = "\x1b[92m%s > \x1b[0m", -- shell prompt, %s will be replaced with working directory. example: "%s > " turns to "/current/working/directory > "
|
||||||
["path"] = { -- default locations where programs will be run from
|
["path"] = { -- default locations where programs will be run from
|
||||||
"/halyde/apps/"
|
"/halyde/apps/"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local loadfile = ...
|
local loadfile = ...
|
||||||
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
|
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
|
||||||
|
|
||||||
_G._OSVERSION = "Halyde 0.7.0"
|
_G._OSVERSION = "Halyde 0.8.0"
|
||||||
|
|
||||||
function _G.import(module, ...)
|
function _G.import(module, ...)
|
||||||
local args = table.pack(...)
|
local args = table.pack(...)
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ _G.shell = {}
|
|||||||
_G.shell.workingDirectory = shellcfg["defaultWorkingDirectory"]
|
_G.shell.workingDirectory = shellcfg["defaultWorkingDirectory"]
|
||||||
_G.shell.aliases = shellcfg["aliases"]
|
_G.shell.aliases = shellcfg["aliases"]
|
||||||
|
|
||||||
local function parseCommand(command)
|
function _G.shell.run(command)
|
||||||
|
checkArg(1, command, "string")
|
||||||
if shell.aliases[command:match("[^ ]+")] then
|
if shell.aliases[command:match("[^ ]+")] then
|
||||||
local _, cmdend = command:find("[^ ]+")
|
local _, cmdend = command:find("[^ ]+")
|
||||||
command = shell.aliases[command:match("[^ ]+")] .. command:sub(cmdend + 1)
|
command = shell.aliases[command:match("[^ ]+")] .. command:sub(cmdend + 1)
|
||||||
@@ -79,5 +80,5 @@ while true do
|
|||||||
-- termlib.cursorPosX = #(shell.workingDirectory .. " > ")
|
-- termlib.cursorPosX = #(shell.workingDirectory .. " > ")
|
||||||
-- termlib.cursorPosY = termlib.cursorPosY - 1
|
-- termlib.cursorPosY = termlib.cursorPosY - 1
|
||||||
local shellCommand = read()
|
local shellCommand = read()
|
||||||
parseCommand(shellCommand)
|
shell.run(shellCommand)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user