1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-06-26 07:02:55 +00:00

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
This commit is contained in:
SquidDev 2017-08-02 22:04:57 +01:00
parent 579f7443a8
commit 5df97e5133

View File

@ -237,9 +237,8 @@ function shell.resolveProgram( _sCommand )
end end
-- If the path is a global path, use it directly -- If the path is a global path, use it directly
local sStartChar = string.sub( _sCommand, 1, 1 ) if _sCommand:find("/") or _sCommand:find("\\") then
if sStartChar == "/" or sStartChar == "\\" then local sPath = shell.resolve( _sCommand )
local sPath = fs.combine( "", _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath return sPath
else else
@ -299,9 +298,9 @@ function shell.programs( _bIncludeHidden )
end end
local function completeProgram( sLine ) 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 -- Add programs from the root
return fs.complete( sLine, "", true, false ) return fs.complete( sLine, sDir, true, false )
else else
local tResults = {} local tResults = {}
@ -318,6 +317,16 @@ local function completeProgram( sLine )
end end
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
if not tSeen[ sResult ] then
local sResult = tDirs[i]
table.insert (tResults, sResult )
tSeen [ sResult ] = true
end
end
-- Add programs from the path -- Add programs from the path
local tPrograms = shell.programs() local tPrograms = shell.programs()
for n=1,#tPrograms do for n=1,#tPrograms do