mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
feature(console) cd to couple-words-names directories
This commit is contained in:
parent
b1aea5f7ad
commit
0b4efe42a2
1 changed files with 36 additions and 35 deletions
|
|
@ -106,8 +106,8 @@
|
|||
connName, ret,
|
||||
|
||||
isVolume = win.isChangeVolume(command),
|
||||
isCD = command.match(new RegExp('^cd ')),
|
||||
isCDWin = command.match(new RegExp('^cd ', 'i')),
|
||||
isCD = command.match(new RegExp('^cd ?')),
|
||||
isCDWin = command.match(new RegExp('^cd ?', 'i')),
|
||||
|
||||
symbolsExec = ['*', '&', '{', '}', '|', '\'', '"'],
|
||||
isSymbol = Util.isContainStr(command, symbolsExec),
|
||||
|
|
@ -276,21 +276,35 @@
|
|||
}
|
||||
|
||||
function onCD(command, currDir, callback) {
|
||||
var isChangeVolume = win.isChangeVolume(command),
|
||||
var CD = 'cd ',
|
||||
isChangeVolume = win.isChangeVolume(command),
|
||||
isVolume = win.isVolume(command),
|
||||
paramDir = Util.rmStr(command, 'cd '),
|
||||
isRootOrHome = equalPart(paramDir, ['/', '~']);
|
||||
paramDir = Util.rmStrOnce(command, [CD, 'cd']),
|
||||
isRoot = paramDir === '/',
|
||||
isHome = paramDir === '~' && !WIN;
|
||||
|
||||
if (!isRootOrHome && !isChangeVolume || isVolume) {
|
||||
command = dropFirstWord(paramDir);
|
||||
if (isHome) {
|
||||
paramDir = process.env.HOME;
|
||||
command = 'cd ' + paramDir;
|
||||
}
|
||||
|
||||
if (!paramDir && !WIN)
|
||||
paramDir = '.';
|
||||
|
||||
if (!isHome && !isRoot && !isChangeVolume || isVolume) {
|
||||
paramDir = getFirstWord(paramDir);
|
||||
command = Util.rmStrOnce(command, [
|
||||
CD,
|
||||
'\'' + paramDir + '\'',
|
||||
'"' + paramDir + '"',
|
||||
]);
|
||||
|
||||
paramDir = path.join(currDir, paramDir);
|
||||
|
||||
command = 'cd ' + paramDir + command;
|
||||
command = CD + '"' + paramDir + '" ' + command;
|
||||
}
|
||||
|
||||
exec(command, {cwd : paramDir}, function (error, stdout, stderr) {
|
||||
exec(command, {cwd: paramDir}, function (error, stdout, stderr) {
|
||||
var path = paramDir,
|
||||
errorStr = '';
|
||||
|
||||
|
|
@ -310,41 +324,28 @@
|
|||
}
|
||||
|
||||
function getFirstWord(str) {
|
||||
var number, word,
|
||||
is = Util.isString(str);
|
||||
|
||||
Util.checkArgs(arguments, ['str']);
|
||||
var word, result,
|
||||
regExp = /^(.*?)\s/,
|
||||
regExpQuotes = /^"(.*)"\s?/,
|
||||
is = Util.isString(str);
|
||||
|
||||
if (is) {
|
||||
number = str.indexOf(' ');
|
||||
result = str.match(regExpQuotes);
|
||||
|
||||
if (~number)
|
||||
word = str.substr(0, number);
|
||||
else
|
||||
if (result) {
|
||||
word = result[1];
|
||||
} else {
|
||||
result = str.match(regExp);
|
||||
word = result && result[1];
|
||||
}
|
||||
|
||||
if (!word)
|
||||
word = str;
|
||||
}
|
||||
|
||||
return word;
|
||||
}
|
||||
|
||||
function dropFirstWord(str) {
|
||||
var number,
|
||||
is = Util.isString(str);
|
||||
|
||||
Util.checkArgs(arguments, ['str']);
|
||||
|
||||
if (is) {
|
||||
number = str.indexOf(' ');
|
||||
|
||||
if (~number)
|
||||
str = str.substr(number + 1);
|
||||
else
|
||||
str = '';
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
function log(connNum, str, typeParam) {
|
||||
var ret,
|
||||
type = ' ';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue