Skip to content

Commit

Permalink
Add 'Open in Integrated Terminal' context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
formulahendry committed Feb 10, 2017
1 parent 52464f2 commit 3312f18
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ From v0.0.4, this extension will have limited updates for bug fix or feature dev
* Run the selected commands in Text Editor
* Stop the running commands
* View output in Output Window
* Open Integrated Terminal at current file's directory

## Usages

Expand All @@ -23,6 +24,10 @@ From v0.0.4, this extension will have limited updates for bug fix or feature dev

![Usage](images/usage.gif)

* To open Integrated Terminal at current file's directory, use shortcut `Ctrl+Alt+O`, or press `F1` and then select/type `Open in Integrated Terminal`, or right click in Text Editor/Explorer and then click `Open in Integrated Terminal` in context menu

![Open](images/open.gif)

## Telemetry data
By default, telemetry data collection is turned on. To disable it, update the settings.json as below:
```json
Expand All @@ -32,6 +37,9 @@ By default, telemetry data collection is turned on. To disable it, update the se
```

## Change Log
### 0.0.7
* Add 'Open in Integrated Terminal' context menu

### 0.0.6
* Upgrade applicationinsights npm since [telemetry data requires HTTPS](https://azure.microsoft.com/en-us/updates/application-insights-telemetry-data-now-requires-https-with-shutdown-of-http-data-collectors/)

Expand Down
Binary file added images/open.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 29 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "terminal",
"displayName": "Terminal",
"description": "Terminal for Visual Studio Code",
"version": "0.0.6",
"version": "0.0.7",
"publisher": "formulahendry",
"icon": "images/logo.png",
"engines": {
"vscode": "^1.0.0"
"vscode": "^1.6.0"
},
"categories": [
"Other",
Expand All @@ -16,7 +16,8 @@
"Terminal",
"Shell",
"Bash",
"CMD"
"CMD",
"powershell"
],
"bugs": {
"url": "https://github.com/formulahendry/vscode-terminal/issues",
Expand All @@ -28,7 +29,8 @@
"url": "https://github.com/formulahendry/vscode-terminal.git"
},
"activationEvents": [
"onCommand:terminal.run"
"onCommand:terminal.run",
"onCommand:terminal.open"
],
"main": "./out/src/extension",
"contributes": {
Expand All @@ -40,6 +42,10 @@
{
"command": "terminal.stop",
"title": "Stop Terminal Command"
},
{
"command": "terminal.open",
"title": "Open in Integrated Terminal"
}
],
"keybindings": [
Expand All @@ -50,8 +56,27 @@
{
"command": "terminal.stop",
"key": "ctrl+alt+c"
},
{
"command": "terminal.open",
"key": "ctrl+alt+o"
}
],
"menus": {
"editor/context": [
{
"when": "!inOutput",
"command": "terminal.open",
"group": "navigation@1"
}
],
"explorer/context": [
{
"command": "terminal.open",
"group": "navigation@1"
}
]
},
"configuration": {
"type": "object",
"title": "Terminal configuration",
Expand Down
25 changes: 25 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import * as path from 'path';
import { AppInsightsClient } from './appInsightsClient';

// this method is called when your extension is activated
Expand All @@ -22,8 +23,13 @@ export function activate(context: vscode.ExtensionContext) {
terminal.stop();
});

let open = vscode.commands.registerCommand('terminal.open', (fileUri) => {
terminal.open(fileUri);
});

context.subscriptions.push(run);
context.subscriptions.push(stop);
context.subscriptions.push(open);
}

// this method is called when your extension is deactivated
Expand Down Expand Up @@ -74,6 +80,25 @@ class Terminal {
}
}

public open(fileUri?: vscode.Uri): void {
let filePath: string;
if (!fileUri || typeof fileUri.fsPath !== 'string') {
let activeEditor = vscode.window.activeTextEditor;
if (activeEditor && !activeEditor.document.isUntitled) {
filePath = activeEditor.document.fileName;
}
} else {
filePath = fileUri.fsPath;
}

this._appInsightsClient.sendEvent("open");
let terminal = vscode.window.createTerminal();
terminal.show(false);
if (filePath) {
terminal.sendText(`cd "${path.dirname(filePath)}"`);
}
}

private getCommands(): string[] {
let editor = vscode.window.activeTextEditor;
if (!editor) {
Expand Down

0 comments on commit 3312f18

Please sign in to comment.