Difference between revisions of "Shell.programs"

From ComputerCraft Wiki
Jump to: navigation, search
(Fixed the example. Requires mention of what it returns and arguments, and visual fixes.)
Line 1: Line 1:
 
{{Stub}}  
 
{{Stub}}  
Shell.programs is a shell command used in the dir command in default CC.
+
Shell.programs is a shell command used to list possible programs you can run, from programs that are in your current directory and programs that have an alias.
  
 
== Example ==
 
== Example ==
function shell.programs( _bIncludeHidden )
+
textutils.tabulate(shell.programs()) -- Would list all the programs like running the program "programs"
    local tItems = {}
+
textutils.tabulate(shell.programs(true)) -- Would list all programs including hidden ones that have a . prefix
    -- Add programs from the path
+
    for sPath in string.gmatch(sPath, "[^:]+") do
+
        sPath = shell.resolve( sPath )
+
        if fs.isDir( sPath ) then
+
            local tList = fs.list( sPath )
+
            for n,sFile in pairs( tList ) do
+
                if not fs.isDir( fs.combine( sPath, sFile ) ) and
+
                    (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
+
                    tItems[ sFile ] = true
+
                end
+
            end
+
        end
+
    end
+
   
+
    -- Sort and return
+
    local tItemList = {}
+
    for sItem, b in pairs( tItems ) do
+
        table.insert( tItemList, sItem )
+
    end
+
    table.sort( tItemList )
+
    return tItemList
+
end
+

Revision as of 05:35, 20 April 2013

This page is a stub.
Please help us by expanding it.

Shell.programs is a shell command used to list possible programs you can run, from programs that are in your current directory and programs that have an alias.

Example

textutils.tabulate(shell.programs()) -- Would list all the programs like running the program "programs" textutils.tabulate(shell.programs(true)) -- Would list all programs including hidden ones that have a . prefix