1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-04-15 15:23:13 +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
-- 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
if not tSeen[ sResult ] then
local sResult = tDirs[i]
table.insert (tResults, sResult )
tSeen [ sResult ] = true
end
end
-- Add programs from the path
local tPrograms = shell.programs()
for n=1,#tPrograms do