This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lifewcody's profile picture

shell.programs Question

Started by lifewcody, 24 January 2015 - 09:42 PM
lifewcody #1
Posted 24 January 2015 - 10:42 PM
Right now I have a disk connected via network cable and about 20 computers boot off of it. Here is what it contains:


shell.setPath("/os")

On the computer there is /os

and on the computer I have:

/os
/os/rom
/os/rom/programs

and apparently shell.programs does not recognize my 'programs' folder, so I have to set an alias for every program. Is there any way around this?
Bomb Bloke #2
Posted 24 January 2015 - 11:14 PM
Looking at the shell source, it appears that aliases are indeed geared for use as shortcuts to files, not folders.

I suppose you could override shell.programs() in startup. Define a new version of the function - one that calls the original, adds the files from your extra programs folder to the output, then returns the result.

local oldPrograms = shell.programs

function shell.programs(_bIncludeHidden)
  local tItemList = oldPrograms(_bIncludeHidden)

  -- Get the list from /os/rom/programs, add it to tItemList, return it
lifewcody #3
Posted 24 January 2015 - 11:50 PM
Looking at the shell source, it appears that aliases are indeed geared for use as shortcuts to files, not folders.

I suppose you could override shell.programs() in startup. Define a new version of the function - one that calls the original, adds the files from your extra programs folder to the output, then returns the result.

local oldPrograms = shell.programs

function shell.programs(_bIncludeHidden)
  local tItemList = oldPrograms(_bIncludeHidden)

  -- Get the list from /os/rom/programs, add it to tItemList, return it

I commented out all my aliases for my programs and added:


function shell.programs()
  local tbl = {}
  local programList = fs.list("/os/.rom/programs/")
  for _, program in ipairs(programList) do
    table.insert(tbl, program)
  end
  return tbl
end
textutils.pagedTabulate(shell.programs())

but this returns nothing
Quintuple Agent #4
Posted 25 January 2015 - 12:29 AM
I don't really ever overwrite functions, but I believe it should be

shell.programs= function ()
instead of

function shell.programs()
If you are wanting to replace the original shell.programs() with your new code.

However I am not sure, I think the original should work since var=function () is equivalent to function var()

Edit: 2 things:
1. You have a '.', I assume that is on purpose so it is a hidden file, but just in case it was not intended and you did not notice.
2. Just for fun try pairs instead of ipairs, should not make a difference but you never know.
Edited on 24 January 2015 - 11:41 PM
Bomb Bloke #5
Posted 25 January 2015 - 01:20 AM
However I am not sure, I think the original should work since var=function () is equivalent to function var()

They're not exactly the same (under certain circumstances: see this guide), but in this case it doesn't matter.

Likewise, ipairs should be suitable here. I reckon you hit the nail with the ".rom" thing.
lifewcody #6
Posted 25 January 2015 - 01:46 AM
However I am not sure, I think the original should work since var=function () is equivalent to function var()

They're not exactly the same (under certain circumstances: see this guide), but in this case it doesn't matter.

Likewise, ipairs should be suitable here. I reckon you hit the nail with the ".rom" thing.

.rom was intentional because I did not want the client of the computer seeing it
Bomb Bloke #7
Posted 25 January 2015 - 01:55 AM
How about we simplify things?:

function shell.programs()
  return fs.list("/os/.rom/programs/")
end
textutils.pagedTabulate(shell.programs())
lifewcody #8
Posted 25 January 2015 - 01:59 AM
However I am not sure, I think the original should work since var=function () is equivalent to function var()

They're not exactly the same (under certain circumstances: see this guide), but in this case it doesn't matter.

Likewise, ipairs should be suitable here. I reckon you hit the nail with the ".rom" thing.

.rom was intentional because I did not want the client of the computer seeing it

Now say if I have a program with the directory of: /os/.rom/programs/test
and I type: test
I get: No such program, how would I make it so when I type: test
it goes to: /os/.rom/programs/test
Bomb Bloke #9
Posted 25 January 2015 - 02:38 AM
Looks like you really want to make use of shell.setPath():

shell.setPath(shell.getPath()..":/os/.rom/programs")
Edited on 25 January 2015 - 01:42 AM