Jump to content




shell.programs Question


  • You cannot reply to this topic
8 replies to this topic

#1 lifewcody

  • Members
  • 143 posts
  • Locationstill looking....

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?

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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


#3 lifewcody

  • Members
  • 143 posts
  • Locationstill looking....

Posted 24 January 2015 - 11:50 PM

View PostBomb Bloke, on 24 January 2015 - 11:14 PM, said:

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

#4 Quintuple Agent

  • Members
  • 107 posts
  • LocationThis page

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 by Quintuple Agent, 25 January 2015 - 12:41 AM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 25 January 2015 - 01:20 AM

View PostQuintuple Agent, on 25 January 2015 - 12:29 AM, said:

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.

#6 lifewcody

  • Members
  • 143 posts
  • Locationstill looking....

Posted 25 January 2015 - 01:46 AM

View PostBomb Bloke, on 25 January 2015 - 01:20 AM, said:

View PostQuintuple Agent, on 25 January 2015 - 12:29 AM, said:

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

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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())


#8 lifewcody

  • Members
  • 143 posts
  • Locationstill looking....

Posted 25 January 2015 - 01:59 AM

View Postjubba890, on 25 January 2015 - 01:46 AM, said:

View PostBomb Bloke, on 25 January 2015 - 01:20 AM, said:

View PostQuintuple Agent, on 25 January 2015 - 12:29 AM, said:

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

#9 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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 by Bomb Bloke, 25 January 2015 - 02:42 AM.






3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users