feature(console) change directory to ~ + wildcard

This commit is contained in:
coderaiser 2014-08-09 05:58:20 -04:00
parent f8cad8f5f4
commit cfbeb27c0a

View file

@ -38,13 +38,7 @@
HELP = {
stdout : CLOUDCMD + ' exit \n' +
CLOUDCMD + ' update \n',
},
glob = function(callback) {callback(null, [])};
Util.exec.try(function() {
glob = require('glob');
});
};
/**
* function listen on servers port
@ -284,13 +278,13 @@
function onCD(command, currDir, callback) {
var CD = 'cd ',
HOME = process.env.HOME,
isChangeVolume = win.isChangeVolume(command),
isVolume = win.isVolume(command),
paramDir = Util.rmStrOnce(command, [CD, 'cd']),
regStrEnd = getRegStrEnd(),
regStrHome = '^~$|^~',
regExpHome = new RegExp(regStrHome + regStrEnd),
regExpHome = new RegExp('^~'),
isWildCard = Util.isContainStr(paramDir, ['*', '?']),
isHome = paramDir.match(regExpHome) && !WIN,
@ -314,15 +308,17 @@
};
if (isHome) {
paramDir = process.env.HOME;
command = command.replace('~', paramDir);
command = command.replace('~', HOME);
paramDir = paramDir.replace('~', HOME);
}
if (!paramDir && !WIN)
paramDir = '.';
if (!isHome && !isChangeVolume || isVolume) {
if (!isChangeVolume || isVolume) {
paramDir = getFirstWord(paramDir);
paramDir = path.normalize(paramDir);
command = Util.rmStrOnce(command, [
CD,
paramDir,
@ -330,7 +326,7 @@
'"' + paramDir + '"',
]);
if (paramDir !== '/')
if (!isHome && paramDir !== '/')
paramDir = path.join(currDir, paramDir);
if (isWildCard)