Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
shellCommand.ls = function( command ) {
var i , j , pathArray , pathNode , keys , key , width = 0 , columns ;
pathArray = ( this.query.hostname + ':' + this.query.port + this.query.pathname ).split( '/' ) ;
if ( pathArray[ pathArray.length - 1 ] === '' ) { pathArray.pop() ; }
pathNode = tree.path.get( this.pathCompletion , pathArray ) ;
if ( ! pathNode || typeof pathNode !== 'object' ) { return ; }
keys = Object.keys( pathNode ) ;
if ( ! keys.length ) { return ; }
term.italic.dim.blue( "Known resources:\n" ) ;
keys.sort( naturalSort ) ;
for ( i = 0 ; i < keys.length ; i ++ ) { width = Math.max( width , keys[ i ].length ) ; }
width += 2 ;
columns = Math.floor( term.width / width ) ;
//console.log( '\ncolumns:' , columns , width , term.width ) ;
for ( i = 0 ; i < keys.length ; i ++ ) {
key = keys[ i ] ;
j = i % columns ;
term.column( j * width ) ;
if ( i && ! j ) { term( '\n' ) ; }
if ( pathNode[ key ] && typeof pathNode[ key ] === 'object' ) { term.magenta.bold( key ).bold( '/' ) ; }
prefix += typedDir ;
node = pathArray.length ? tree.path.get( this.pathCompletion , pathArray ) : this.pathCompletion ;
//console.log( '\n\nnode:' , node , pathArray ) ;
if ( ! node || typeof node !== 'object' ) { return start ; }
for ( key in node ) {
if ( node[ key ] && typeof node[ key ] === 'object' ) { completion.push( key + '/' ) ; }
else { completion.push( key ) ; }
}
completion = termkit.autoComplete( completion , lastTypedPart , true ) ;
if ( ! Array.isArray( completion ) ) { return prefix + completion ; }
completion.sort( naturalSort ) ;
completion.prefix = prefix ;
return completion ;
} ;
shellCommand.lls = async function( command ) {
var i , j , files , file , width = 0 , columns ;
try {
files = await fsKit.readdirAsync( this.cwd , { slash: true } ) ;
}
catch ( error ) {
term.red( "Can't access directory %s: %s\n" , this.cwd , error ) ;
return ;
}
files.sort( naturalSort ) ;
term.italic.dim.blue( "Local %s:\n" , this.cwd ) ;
for ( i = 0 ; i < files.length ; i ++ ) { width = Math.max( width , files[ i ].length ) ; }
width += 2 ;
columns = Math.floor( term.width / width ) ;
//console.log( '\ncolumns:' , columns , width , term.width ) ;
for ( i = 0 ; i < files.length ; i ++ ) {
file = files[ i ] ;
j = i % columns ;
term.column( j * width ) ;
if ( i && ! j ) { term( '\n' ) ; }