Skip to content

Instantly share code, notes, and snippets.

@Jordach
Created February 21, 2014 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jordach/88390540522eb1812f59 to your computer and use it in GitHub Desktop.
Save Jordach/88390540522eb1812f59 to your computer and use it in GitHub Desktop.
terminal_version = "0.2"
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 /'
print 'cdir - cdir changes the current directory to a new directory - starting from A:\\, the user types, bacon, then the path becomes A:\\bacon (bacon\\eggs is also legal)'
print 'bdir - bdir allows the user to specify a completely different path - eg, you can go from D:\\bacon to D:\\eggs paths such as bacon\eggs are also legal'
print 'cdrive - cdrive allows the user to change the base drive of the system, eg, from C:\\ to D:\\'
end
if command == "exit" or command == "Exit" then
print 'Exiting Lua terminal.'
i = 0
end
if command == "os" or command == "OS" or command == "Os" then
if user_is_windows == "yes" then
print 'Running Microsoft Windows'
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 == "version" or command == "Version" then
if user_is_windows == "yes" then
os_name = "Microsoft Windows"
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 == "cdir" or command == "Cdir" or command == "CDir" then
if user_is_windows == "yes" then
print 'If you are going to be changing folder (eg, within the current folder) please specify it like this: bacon'
folder_dir = io.read()
working_dir = working_dir .. "\\" .. folder_dir
else
print 'If you are going to be changing folder (eg, within the current folder) please specify it like this: eggs'
folder_dir = io.read()
working_dir = working_dir .. "/" .. folder_dir
end
print ("Working directory is now: " .. working_dir)
end
if command == "bdir" or command == "Bdir" or command == "BDir" then
if user_is_windows == "yes" then
print 'Please select a base dir to return to; eg, "this_folder" at the root of the drive, or folders in folders - eg, "bacon\\eggs"'
folder_dir = io.read()
working_dir = system_drive .. folder_dir
else
print 'Please select a base dir to return to; eg, "this_folder" at the root of the drive, or folders in folders - eg, "bacon/eggs"'
folder_dir = io.read()
working_dir = system_drive .. folder_dir
end
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 == "cdrive" or command == "Cdrive" or command == "CDrive" then
if user_is_windows == "yes" then
print 'Please select the system drive for the terminal to be using, eg, C:\\'
system_drive = io.read()
if folder_dir == "nil" then
working_dir = system_drive
else
working_dir = system_drive .. folder_dir
end
else
print 'Please select a drive for the terminal to be using, eg, sda1'
system_drive = io.read()
system_drive = "/mnt/" .. system_drive
if folder_dir == "nil" then
working_dir = system_drive .. "/"
else
working_dir = system_drive .. "/" .. folder_dir
end
end
end
if command == "contributors" or command == "Contributors" then
if no_of_contribs == 1 then
print (contributors[1])
else
for j=1, 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
command = "nil"
until i == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment