From 7cf9fad27ecce7e0fcec1310f514f88eeabb0909 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 25 Jul 2014 10:52:28 -0400 Subject: [PATCH] feature(console) change directory and do something after ";, &&, ||" --- lib/server/console.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/server/console.js b/lib/server/console.js index 8a5f1e64..1fa05ae8 100644 --- a/lib/server/console.js +++ b/lib/server/console.js @@ -281,8 +281,9 @@ isVolume = win.isVolume(command), paramDir = Util.rmStrOnce(command, [CD, 'cd']), - regExpHome = /^~$|^~\s/, - isRoot = paramDir === '/', + regStrEnd = getRegStrEnd(), + regStrHome = '^~$|^~', + regExpHome = new RegExp(regStrHome + regStrEnd), isHome = paramDir.match(regExpHome) && !WIN; if (isHome) { @@ -293,17 +294,19 @@ if (!paramDir && !WIN) paramDir = '.'; - if (!isHome && !isRoot && !isChangeVolume || isVolume) { + if (!isHome && !isChangeVolume || isVolume) { paramDir = getFirstWord(paramDir); command = Util.rmStrOnce(command, [ CD, + paramDir, '\'' + paramDir + '\'', '"' + paramDir + '"', ]); - paramDir = path.join(currDir, paramDir); + if (paramDir !== '/') + paramDir = path.join(currDir, paramDir); - command = CD + '"' + paramDir + '" ' + command; + command = CD + '"' + paramDir + '" ' + command; } exec(command, {cwd: paramDir}, function (error, stdout, stderr) { @@ -327,8 +330,11 @@ function getFirstWord(str) { var word, result, - regExp = /^(.*?)\s/, - regExpQuotes = /^"(.*)"\s?/, + regStrEnd = getRegStrEnd(), + regStr = '^(.*?)', + regStrQuotes = '^"(.*)"', + regExp = new RegExp(regStr + regStrEnd), + regExpQuotes = new RegExp(regStrQuotes + regStrEnd + '?'), is = Util.isString(str); if (is) { @@ -348,6 +354,12 @@ return word; } + function getRegStrEnd() { + var regStrEnd = '(\\s|\\;|&&|\\|\\|)'; + + return regStrEnd; + } + function log(connNum, str, typeParam) { var ret, type = ' ';