Skip to content

Commit

Permalink
Change executor if the Integrated Terminal is PowerShell on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
formulahendry committed Feb 6, 2017
1 parent 234b087 commit 64c5efd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 0.6.9
* Change executor if the Integrated Terminal is PowerShell on Windows

### 0.6.8
* Add support for Haxe

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ e.g. To set the executor PATH for ruby, php and html:
"perl": "perl",
"ruby": "C:\\Ruby23-x64\\bin\\ruby.exe",
"go": "go run",
".html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
"html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "gcc $fullFileName && ./a.out"
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
}
}
```
**Supported customized parameters**
* $workspaceRoot: The path of the folder opened in VS Code
* $dir: The directory of the code file being run
* $dirWithoutTrailingSlash: The directory of the code file being run without a trailing slash
* $fullFileName: The full name of the code file being run
* $fileName: The base name of the code file being run, that is the file without the directory
* $fileNameWithoutExt: The base name of the code file being run without its extension
Expand Down Expand Up @@ -133,6 +134,7 @@ To set whether to show extra execution message like [Running] ... and [Done] ...
## Note
* To run C# script, you need to install [scriptcs](http://scriptcs.net/)
* To run TypeScript, you need to install [ts-node](https://github.com/TypeStrong/ts-node)
* To run Clojure, you need to install [Leiningen](https://leiningen.org/) and [lein-exec](https://github.com/kumarshantanu/lein-exec)

## Telemetry data
By default, telemetry data collection is turned on to understand user behavior to improve this extension. To disable it, update the settings.json as below:
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "code-runner",
"displayName": "Code Runner",
"description": "Run code snippet/file for C, C++, Java, JS, PHP, Python, Perl, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F#, C#, VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml, R, AppleScript, Elixir, VB.NET, Clojure, Haxe",
"version": "0.6.8",
"version": "0.6.9",
"publisher": "formulahendry",
"icon": "images/logo.png",
"engines": {
Expand Down Expand Up @@ -104,7 +104,7 @@
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
Expand All @@ -126,7 +126,7 @@
"code-runner.executorMapByFileExtension": {
"type": "object",
"default": {
".vb": "cd $dir && vbc /nologo $fileName && $fileNameWithoutExt",
".vb": "cd $dir && vbc /nologo $fileName && $dir$fileNameWithoutExt",
".vbs": "cscript //Nologo",
".scala": "scala",
".jl": "julia",
Expand Down
17 changes: 17 additions & 0 deletions src/codeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,28 @@ export class CodeManager {
return (cmd != executor ? cmd : executor + (appendFile ? ' ' + this.quoteFileName(this._codeFile) : ''));
}

private changeExecutorFromCmdToPs(executor: string): string {
if (os.platform() === 'win32') {
let windowsShell = vscode.workspace.getConfiguration('terminal').get<string>('integrated.shell.windows');
if (windowsShell && windowsShell.toLowerCase().indexOf('powershell') > -1 && executor.indexOf(' && ') > -1) {
let replacement = '; if ($?) {';
executor = executor.replace('&&', replacement);
replacement = '} ' + replacement;
executor = executor.replace(/&&/g, replacement);
executor = executor.replace(/\$dir\$fileNameWithoutExt/g, '.\\$fileNameWithoutExt');
return executor + ' }';
}
}
return executor;
}

private executeCommandInTerminal(executor: string, appendFile: boolean = true) {
if (this._terminal === null) {
this._terminal = vscode.window.createTerminal('Code');
}
this._terminal.show(true);
executor = this.changeExecutorFromCmdToPs(executor);
this._appInsightsClient.sendEvent(executor);
let command = this.getFinalCommandToRunCodeFile(executor, appendFile);
this._terminal.sendText(command);
}
Expand Down

0 comments on commit 64c5efd

Please sign in to comment.