Skip to content

Instantly share code, notes, and snippets.

@foopis23
Last active July 3, 2023 21:41
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 foopis23/f3de530e1a1ccd05a422e66f9d139390 to your computer and use it in GitHub Desktop.
Save foopis23/f3de530e1a1ccd05a422e66f9d139390 to your computer and use it in GitHub Desktop.
A start up script to make craftos more like unix
local expect = dofile("rom/modules/main/cc/expect.lua").expect
if not fs.exists("/bin") then
fs.makeDir("/bin")
end
if not fs.exists("/home") then
fs.makeDir("/home")
end
local function custom_dir_completion(shell, _, text, _)
if text == nil then
text = ""
end
-- string replace replace ~ with /home
text = string.gsub(text, "~", "/home")
return fs.complete(text, shell.dir(), false, true)
end
local function custom_shell_resolve(path)
expect(1, path, "string")
local sStartChar = string.sub(path, 1, 1)
if sStartChar == "/" or sStartChar == "\\" then
return fs.combine("", path)
elseif (sStartChar == "~") then
return fs.combine("/home", string.sub(path, 2))
else
return fs.combine(shell.dir(), path)
end
end
-- update path to include /bin
local path = shell.path()
path = path .. ":/bin"
shell.setPath(path)
-- update shell.resolve ~ to /home
shell.resolve = custom_shell_resolve
-- update tab completion to include ~
shell.setCompletionFunction("rom/programs/cd.lua", custom_dir_completion)
-- start in /home
shell.setDir("/home")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment