v0.8.0 - Added help and fetch.
This commit is contained in:
+4
-1
@@ -2,7 +2,10 @@ local args = {...}
|
||||
local file = args[1]
|
||||
args = nil
|
||||
local fs = import("filesystem")
|
||||
|
||||
if not file then
|
||||
shell.run("help cat")
|
||||
return
|
||||
end
|
||||
if file:sub(1, 1) ~= "/" then
|
||||
file = shell.workingDirectory .. file
|
||||
end
|
||||
|
||||
+5
-6
@@ -11,15 +11,14 @@ if toFile:sub(1, 1) ~= "/" then
|
||||
end
|
||||
if fromFile == toFile then
|
||||
print("\27[91mSource and destination are the same.")
|
||||
return
|
||||
end
|
||||
if not fs.exists(fromFile) then
|
||||
print("\27[91mSource file does not exist.")
|
||||
return
|
||||
end
|
||||
if fs.exists(toFile) then
|
||||
print("Destination file already exists. Overwrite it? [Y/n] ", false)
|
||||
if read():lower() == "n" then
|
||||
print("Aborted.")
|
||||
return
|
||||
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
|
||||
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.
|
||||
+3
-6
@@ -15,11 +15,8 @@ end
|
||||
if not fs.exists(fromFile) then
|
||||
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
|
||||
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
|
||||
fs.rename(fromFile, toFile)
|
||||
|
||||
Reference in New Issue
Block a user