Permalink
Browse files

Tweak shell program resolution slightly

 - Path containing '/' or '\' are resolved relative to the current
   directory, rather than using the path. Paths starting with '/' still
   resolve relative to the root directory.
 - Shell completion will also include sub-directories of the current
   directory.

Closes #219
  • Loading branch information...
SquidDev committed Aug 2, 2017
1 parent 579f744 commit 4df92ff7f05a1c64e82697159cadbcabd06a7fa8
Showing with 14 additions and 5 deletions.
  1. +14 −5 src/main/resources/assets/computercraft/lua/rom/programs/shell.lua
@@ -237,9 +237,8 @@ function shell.resolveProgram( _sCommand )
end
-- If the path is a global path, use it directly
local sStartChar = string.sub( _sCommand, 1, 1 )
if sStartChar == "/" or sStartChar == "\\" then
local sPath = fs.combine( "", _sCommand )
if _sCommand:find("/") or _sCommand:find("\\") then
local sPath = shell.resolve( _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
else
@@ -299,9 +298,9 @@ function shell.programs( _bIncludeHidden )
end
local function completeProgram( sLine )
if #sLine > 0 and string.sub( sLine, 1, 1 ) == "/" then
if #sLine > 0 and (sLine:find("/") or sLine:find("\\")) then
-- Add programs from the root
return fs.complete( sLine, "", true, false )
return fs.complete( sLine, sDir, true, false )
else
local tResults = {}
@@ -318,6 +317,16 @@ local function completeProgram( sLine )
end
end
-- Add all subdirectories. We don't include files as they will be added in the block below
local tDirs = fs.complete( sLine, sDir, false, false )
for i = 1, #tDirs do
local sResult = tDirs[i]
if not tSeen[ sResult ] then
table.insert (tResults, sResult )
tSeen [ sResult ] = true
end
end
-- Add programs from the path
local tPrograms = shell.programs()
for n=1,#tPrograms do

0 comments on commit 4df92ff

Please sign in to comment.