Coming from a UNIX background, there's some muscle memory that's hard to get rid of. Thus, I've written a small script that adds some bash-like commands to the command line for Mini Micro. Just add the code below to your /usr/startup.ms
file.
cd
now has limited autocomplete
touch
creates a blank miniscript file
mim
(like vim) creates a file in place and calls edit
or calls edit
on an existing file
reload
is basically reset
but also loads this file again
buildCache
enables the limited autocomplete and could probably be added to commands other than cd
ls
= dir
mv
= file.move
cp
= file.copy
rm
= delete
buildCache = function()
for item in file.children(".")
item = item.remove("/")
item = item.remove(".ms")
globals[item] = item
dirItems.push(item)
end for
end function
buildCache
cd = function(path)
if path == null then
path = "/usr"
end if
for item in globals.indexes
localIndex = dirItems.indexOf(item)
if localIndex != null then
globals.remove(item)
dirItems.remove(localIndex)
end if
end for
file.setdir path
buildCache
end function
touch = function(path)
if not path then
print "Filename not specified; unable to save"
return
end if
if path[-3:] != ".ms" then path = path + ".ms"
if path[0] != "/" then path = file.child(file.curdir, path)
if file.exists(path) then
print "File already exists: " + path
return
end if
_fileWrite(path, "")
print "Created file " + path
end function
rm = function(path)
if not path then
print "Filename not specified; unable to save"
return
end if
if path[-3:] != ".ms" then path = path + ".ms"
if path[0] != "/" then path = file.child(file.curdir, path)
if not file.exists(path) then
print "File does not exist: " + path
return
end if
delete path
print "Deleted " + path
end function
ls = function()
dir
end function
cp = function(arg0, arg1)
file.copy arg0, arg1
end function
mv = function(arg0, arg1)
file.move arg0, arg1
end function
// vim-like command
mim = function(path)
if path[-3:] != ".ms" then path = path + ".ms"
if path[0] != "/" then path = file.child(file.curdir, path)
if file.exists(path) then
load path
edit
else
touch(path)
load path
edit
end if
end function
reload = function()
globals._source = []
globals._sourceFile = null
_restoreGlobals
env.importPaths = [".", "/usr/lib", "/sys/lib"]
print("Program source cleared and reset")
load "/usr/startup"
run
return null
end function```