Skip to content

Instantly share code, notes, and snippets.

@Jordach
Last active April 27, 2022 07:48
Show Gist options
  • Save Jordach/6932906 to your computer and use it in GitHub Desktop.
Save Jordach/6932906 to your computer and use it in GitHub Desktop.
LuaTerminal
terminal_version = "0.1.4"
system_drive = "nil" --possibly irrelevant for UNIX systems. todo: these need to be loaded at startup
working_dir = "nil"
folder_dir = "nil"
os_name = "nil"
user_is_windows = "unsure" --until proven guilty....fact: Lua Terminal was made on windows.
i = 1 --used to keep the main loop running, please do not modify.
if package.config:sub(1,1) == "\\" then --\ is windows, / is UNIX.
user_is_windows = "yes"
else
user_is_windows = "no"
end
no_of_contribs = 1
contributors = {"Jordach"} -- please add to this table if you have contributed to Lua Terminal.
function TerminalVersion()
t_v = "Lua Terminal Version: " .. terminal_version
print (t_v)
end
print (TerminalVersion())
repeat --this is the main terminal loop, so that when the program has finished its command, the command entry returns.
repeat -- repeat is used to enter the command until a legal string (in lua) is entered by the user.
command = io.read()
until command ~= nil
if command == "Help" or command == "help" then
print 'The help command gives information on the following:'
print 'help - help prints information on the commands the Lua Terminal has.'
print 'date - date prints to the terminal as: Day, Month, Year'
print 'exit - exit stops the instance of the Lua Termimal'
print 'version - version is where the terminal prints the Lua Terminal version.'
print 'stopwatch - stopwatch starts a timer and then prints out the value, every subsequent stopwatch will display the time.'
print 'time - time prints the current time in hours, minutes and seconds, it does not include the date.'
print 'mkdir - create a directory with the next line\'s text as the directory name, examples: foldera or "folder with spaces"'
print 'ld - prints all folders in the current directory. cd will be soon supported,'
print 'setup - setup starts a small setup program that will allow the user to set defaults for the Lua Terminal'
--todo: add config file stored in a static location, or be pointed at via the same system as mkdir.
print 'os - os automagically detects the Operating system type and states what it is.'
--note: can only identify MS Windows or a UNIX Like kernel. todo: find method of getting Windows version and Linux distro version.
print 'luacute - luacute will execute the Lua program that is written to the next line; <filename.lua> will run a Lua program within the Lua Terminal. D:/fun/ageguess.lua is also legal.'
print 'execute - execute works just like luacute, except it can activate programs that are not Lua. Paths on Windows must be \\ and not /'
end
if command == "exit" or command == "Exit" then
print 'Exiting Lua terminal.'
i = 0
end
if command == "version" or command == "Version" then
if user_is_windows == "yes" then
print 'Running Microsoft Windows NT'
else
print 'UNIX compliant kernel.'
end
end
if command == "stopwatch" or command == "Stopwatch" then
print(os.clock())
end
if command == "date" or command == "Date" then
print (os.date ("%A, %m %B %Y"))
end
if command == "time" or command == "Time" then
print (os.date("%X"))
end
if command == "os" or command == "OS" or command == "Os" then
if user_is_windows == "yes" then
os_name = "Microsoft Windows NT"
else
os_name = "UNIX compliant kernel"
end
print ("Running Lua Terminal version " .. terminal_version .. " under " .. os_name)
end
if command == "mkdir" or command == "Mkdir" then
repeat
folder_name = io.read()
until folder_name ~= nil
os.execute("cd " .. working_dir)
os.execute(("mkdir %q"):format(folder_name))
end
if command == "setup" or command == "Setup" then
if user_is_windows == "yes" then
print 'Please enter the drive you are going to be using, eg C:\\'
else
print 'Please select the device in /mnt/, eg, sda1/'
end
system_drive = io.read()
if user_is_windows == "yes" then
print 'If you are going to be using a folder to work in, please state it. Please also use \\, an example is: folder\\texts'
else
print 'If you are going to be using a folder to work in, please state it. Please also use /, an example is dev/null' --note: please don't actually work here.
end
folder_dir = io.read()
working_dir = system_drive .. folder_dir
print ('Working directory is now: ' .. working_dir)
end
if command == "ld" or command == "Ld" then
if user_is_windows == "yes" then
print (os.execute("dir " .. working_dir))
else
print (os.execute(ls .. working_dir))
end
end
if command == "contributors" or command == "Contributors" then
if no_of_contribs == 1 then
print (contributors[1])
else
for j=0, no_of_contribs, 1 do print (contributors[j]) end
end
end
if command == "luacute" or command == "Luacute" or command == "LuaCute" then --yes, Lua is pretty damn cute... <3
repeat
luafile = io.read()
until luafile ~= nil
dofile (luafile)
print 'Returned to Lua Terminal'
end
if command == "execute" or command == "Execute" then
repeat
app_path = io.read()
until app_path ~= nil
os.execute(app_path)
print 'Returned to Lua Terminal'
end
until i == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment