Commit 12ac8d61 authored by Medicean's avatar Medicean

(Enhance:Terminal) 新增 PowerShell 模式, 可指定 powershell 作为命令解释器

parent 6d2b0724
......@@ -17,6 +17,16 @@
![aslistcmd.png](https://i.loli.net/2019/04/05/5ca74815a01a4.png)
![aslistcmd_win.png](https://i.loli.net/2019/04/05/5ca74819b276e.png)
* 新增自定义命令 `aspowershell [on|off]`, 开启/关闭 PowerShell 模式
> 如果`ascmd`命令指定的PowerShell解释器文件名中包函`powershell`关键字, 会自动启用 PowerShell 模式, 如下图:
![aspowershell_default](https://i.loli.net/2019/04/05/5ca753673efe7.png)
> 如果指定的 PowerShell 解释器文件名中不包含 `powershell` 关键字, 则需要手动使用该命令,启用 PowerShell 模式。如果关闭了 PowerShell 模式,则会执行出错,如下图:
![aspowershell_switch](https://i.loli.net/2019/04/05/5ca75368d85fa.png)
### 其它
* 修复默认设置保存时导致 bookmarks 清空的问题
......
......@@ -204,6 +204,7 @@ module.exports = {
ashelp: `Usage:
ascmd file\t\tExecute the command with file, eg: ascmd /bin/bash
aslistcmd\t\tList available command interpreters
aspowershell [on|off]\t\tEnable/Disable PowerShell mode, eg: aspowershell on
quit\t\tClose terminal
exit\t\tClose terminal
......@@ -214,6 +215,10 @@ Hot Keys:
Ctrl U\t\tClear the current row
`,
ascmd: (cmd) => antSword.noxss(`Will execute the command with ${cmd}.`),
aspowershell: {
on: "Powershell mode enabled",
off: "Powershell mode disabled",
},
},
},
filemanager: {
......
......@@ -205,6 +205,7 @@ module.exports = {
ashelp: `使用帮助:
ascmd file\t\t指定file来执行命令, eg: ascmd /bin/bash
aslistcmd\t\t列出可使用的命令解释器
aspowershell [on|off]\t\t启用/关闭PowerShell模式, eg: aspowershell on
quit\t\t关闭终端
exit\t\t关闭终端
......@@ -215,6 +216,10 @@ module.exports = {
Ctrl U\t\t清除当前行
`,
ascmd: (cmd) => antSword.noxss(`将使用 ${cmd} 执行命令.`),
aspowershell: {
on: "已启用Powershell模式",
off: "已关闭Powershell模式",
},
},
},
filemanager: {
......
......@@ -40,7 +40,9 @@ class Terminal {
this.term = null;
this.cell = cell;
this.isWin = true;
this.isPowershell = false;
this.sessbin = null;
this.sess_powershell = null;
this.core = new antSword['core'][opts['type']](opts);
this.cache = new antSword['CacheManager'](this.opts['_id']);
......@@ -202,6 +204,17 @@ class Terminal {
}
return;
}
if ( cmd.substr(0,12) === 'aspowershell') {
var _switch = cmd.substr(12).trim().toLowerCase();
if(_switch === "on") {
self.sess_powershell = true;
term.echo(LANG['ascmd']['aspowershell']["on"]);
}else {
self.sess_powershell = false;
term.echo(LANG['ascmd']['aspowershell']["off"]);
}
return;
}
term.pause();
// 是否有缓存
let cacheTag = 'command-' + new Buffer(this.path + cmd).toString('base64');
......@@ -221,6 +234,14 @@ class Terminal {
if(self.sessbin !== null) {
_bin = self.sessbin;
}
if(self.isWin && _bin.indexOf("powershell") > -1) {
self.isPowershell = true
}else{
self.isPowershell = false
}
if(self.sess_powershell !== null) {
self.isPowershell = self.sess_powershell;
}
// 开始执行命令
this.core.request(
this.core.command.exec({
......@@ -272,7 +293,7 @@ class Terminal {
// < 1.0.0 时使用3个参数 completion: (term, value, callback) => {}
completion: (value, callback) => {
callback([
'ashelp', 'ascmd', 'aslistcmd', 'quit', 'exit'
'ashelp', 'ascmd', 'aslistcmd', 'aspowershell', 'quit', 'exit'
].concat(
this.isWin ? [
'dir', 'whoami', 'net', 'ipconfig', 'netstat', 'cls',
......@@ -328,7 +349,7 @@ class Terminal {
parseCmd(cmd, path) {
path = path.replace(/\\\\/g, '\\').replace(/"/g, '\\"').replace(/\\/g, '\\\\');
return (this.isWin
? `cd /d "${path}"&${cmd}&echo [S]&cd&echo [E]`
? this.isPowershell? `cd "${path}";${cmd};echo [S];(pwd).path;echo [E]`:`cd /d "${path}"&${cmd}&echo [S]&cd&echo [E]`
: `cd "${path}";${cmd};echo [S];pwd;echo [E]`
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment