├── .gitignore
├── .vscode
├── launch.json
├── settings.json
└── tasks.json
├── .vscodeignore
├── LICENSE
├── README.md
├── images
└── git-bash-logo.svg
├── package.json
├── src
└── extension.ts
├── start-git-bash-1.0.0.vsix
├── test
├── extension.test.ts
└── index.ts
├── tsconfig.json
└── typings
├── node.d.ts
└── vscode-typings.d.ts
/.gitignore:
--------------------------------------------------------------------------------
1 | out
2 | node_modules
3 | *.vsix
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | // A launch configuration that compiles the extension and then opens it inside a new window
2 | {
3 | "version": "0.1.0",
4 | "configurations": [
5 | {
6 | "name": "Launch Extension",
7 | "type": "extensionHost",
8 | "request": "launch",
9 | "runtimeExecutable": "${execPath}",
10 | "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11 | "stopOnEntry": false,
12 | "sourceMaps": true,
13 | "outDir": "${workspaceRoot}/out/src",
14 | "preLaunchTask": "npm"
15 | },
16 | {
17 | "name": "Launch Tests",
18 | "type": "extensionHost",
19 | "request": "launch",
20 | "runtimeExecutable": "${execPath}",
21 | "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
22 | "stopOnEntry": false,
23 | "sourceMaps": true,
24 | "outDir": "${workspaceRoot}/out/test",
25 | "preLaunchTask": "npm"
26 | }
27 | ]
28 | }
29 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | // Place your settings in this file to overwrite default and user settings.
2 | {
3 | "files.exclude": {
4 | "out": false, // set this to true to hide the "out" folder with the compiled JS files
5 | "*.vsix": true
6 | },
7 | "search.exclude": {
8 | "out": true // set this to false to include "out" folder in search results
9 | },
10 |
11 | "typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | // Available variables which can be used inside of strings.
2 | // ${workspaceRoot}: the root folder of the team
3 | // ${file}: the current opened file
4 | // ${fileBasename}: the current opened file's basename
5 | // ${fileDirname}: the current opened file's dirname
6 | // ${fileExtname}: the current opened file's extension
7 | // ${cwd}: the current working directory of the spawned process
8 |
9 | // A task runner that calls a custom npm script that compiles the extension.
10 | {
11 | "version": "0.1.0",
12 |
13 | // we want to run npm
14 | "command": "npm",
15 |
16 | // the command is a shell script
17 | "isShellCommand": true,
18 |
19 | // show the output window only if unrecognized errors occur.
20 | "showOutput": "silent",
21 |
22 | // we run the custom script "compile" as defined in package.json
23 | "args": ["run", "compile", "--loglevel", "silent"],
24 |
25 | // The tsc compiler is started in watching mode
26 | "isWatching": true,
27 |
28 | // use the standard tsc in watch mode problem matcher to find compile problems in the output.
29 | "problemMatcher": "$tsc-watch"
30 | }
--------------------------------------------------------------------------------
/.vscodeignore:
--------------------------------------------------------------------------------
1 | .vscode/**
2 | typings/**
3 | out/test/**
4 | test/**
5 | src/**
6 | **/*.map
7 | .gitignore
8 | tsconfig.json
9 | vsc-extension-quickstart.md
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Robert923
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # README
2 |
3 | This has now largely been superceeded by built-in VSCode functionality in
4 | [release 1.1.0 (April 2016)](https://code.visualstudio.com/updates/vApril)
5 |
6 | ----
7 |
8 | This small Visual Studio Code extension adds a "bash" commands to VSCode that allows you to start git-bash with the current working folder
9 | as the VSCode workspace's root folder.
10 |
11 | Plugin provides two commands:
12 |
13 | * `bash` will open bash in your current file's directory.
14 | * `bash in workspace` will open bash always in the root workspace directory, despite what file is opened.
15 |
16 | Just press F1 and then type any of above commands to start git-bash.exe.
17 |
18 | **Note that you will need to have git-bash.exe on the environment path.**
19 |
20 | **Enjoy!**
21 |
22 | ## Version 1.1.0
23 | * Updated so that if you have a file open it will open git-bash in the folder of the file,
24 | but if there's no folder it will still default to the workspace root folder.
25 | Thanks to [Leo](https://github.com/leotm) for the idea and pull request! :-)
26 |
27 | ## Version 1.0.4
28 | * Improved error checking when git-bash isn't on the path
29 | * No longer opens an informational message when it opens git-bash (that you then have to close each time, which is annoying).
30 |
--------------------------------------------------------------------------------
/images/git-bash-logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
38 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "start-git-bash",
3 | "displayName": "Start git-bash",
4 | "description": "Adds a bash command to VSCode that allows you to start git-bash in the current workspace's root folder.",
5 | "version": "1.1.0",
6 | "icon": "images/git-bash-logo.svg",
7 | "publisher": "McCarter",
8 | "repository": {
9 | "type" : "git",
10 | "url" : "https://github.com/Robert923/vscode-start-git-bash.git"
11 | },
12 | "engines": {
13 | "vscode": "^1.0.0"
14 | },
15 | "categories": [
16 | "Other"
17 | ],
18 | "activationEvents": [
19 | "onCommand:extension.startGitBash",
20 | "onCommand:extension.startWorkspaceGitBash"
21 | ],
22 | "main": "./out/src/extension",
23 | "contributes": {
24 | "commands": [{
25 | "command": "extension.startGitBash",
26 | "title": "bash"
27 | },
28 | {
29 | "command": "extension.startWorkspaceGitBash",
30 | "title": "bash in workspace"
31 | }]
32 | },
33 | "scripts": {
34 | "vscode:prepublish": "node ./node_modules/vscode/bin/compile",
35 | "compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
36 | "postinstall": "node ./node_modules/vscode/bin/install"
37 | },
38 | "devDependencies": {
39 | "typescript": "^1.8.5",
40 | "vscode": "^0.11.0"
41 | }
42 | }
--------------------------------------------------------------------------------
/src/extension.ts:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | import * as vscode from 'vscode';
3 | import path = require('path');
4 | var spawn = require('child_process').spawn;
5 |
6 | /**
7 | * Attempts to open git-bash at the given path
8 | * @param {string} activateOnPath - The path where git-bash should start
9 | */
10 | function spawnGitBash(activateOnPath:string) : boolean {
11 | // Check pre-conditions
12 | if( !activateOnPath || activateOnPath.length==0 ) return false;
13 | console.log("Attempting to open git-bash in folder: " + activateOnPath);
14 |
15 | // Try and spawn a git-bash.exe process
16 | const pathArg = "--cd=" + activateOnPath;
17 | const gitProcess = spawn('git-bash.exe',[pathArg]);
18 | gitProcess.on('error', function(error) {
19 | const missingGitBash = 'Failed to start bash - is git-bash.exe on the system path?';
20 | console.error(missingGitBash + ' Underlying spawn error: ' + error);
21 | vscode.window.showErrorMessage(missingGitBash);
22 | });
23 |
24 | // Log a message that we think we succeeded in opening a bash window
25 | console.log('Bash started @ "' + activateOnPath + '"');
26 | return true;
27 | }
28 |
29 |
30 | /**
31 | * Start bash in the current VSCode workspace root folder
32 | */
33 | function startBash(forceWorkspace:boolean) {
34 | try {
35 | // If spawn wasn't successfully loaded there's nothing we can do
36 | if( !spawn ) {
37 | vscode.window.showErrorMessage('Could not start bash - no spawn function found (sorry).');
38 | return;
39 | }
40 |
41 | // If there's a file open we'll try and it's directory - even without a workspace
42 | const activeEditor = vscode.window.activeTextEditor;
43 | if( activeEditor!=null && forceWorkspace !== true ) {
44 | const filePath = path.dirname(activeEditor.document.fileName);
45 | spawnGitBash(filePath);
46 | return;
47 | }
48 |
49 | // No open file, try launching git-bash in the root of the current workspace
50 | // http://stackoverflow.com/questions/36587904/how-to-start-bash-in-a-directory-in-windows-bat
51 | // git-bash.exe" --cd=D:\mozdev
52 | const workspace = vscode.workspace;
53 | if( !workspace ) return; // If there's no open work space there's nothing we can do
54 | spawnGitBash(workspace.rootPath);
55 | } catch( e ) {
56 | const errorMessage = 'Sorry, something went wrong with start-git-bash. ';
57 | console.error(errorMessage + e);
58 | vscode.window.showErrorMessage(errorMessage + ' See the VSCode log for details.');
59 | }//catch
60 | }
61 |
62 |
63 | // This method is called when your extension is activated
64 | // The extension will be activated the very first time the command is executed
65 | export function activate(context: vscode.ExtensionContext) {
66 | // The command has been defined in the package.json file
67 | // Now provide the implementation of the command with registerCommand
68 | // The commandId parameter must match the command field in package.json
69 | let disposable = vscode.commands.registerCommand('extension.startGitBash', () => startBash( false ) );
70 | let workspaceDisposable = vscode.commands.registerCommand('extension.startWorkspaceGitBash', () => startBash( true ) );
71 |
72 | context.subscriptions.push(disposable);
73 | context.subscriptions.push(workspaceDisposable);
74 | }
75 |
76 | // This method is called when the extension is deactivated
77 | export function deactivate() {
78 | // Empty
79 | }
--------------------------------------------------------------------------------
/start-git-bash-1.0.0.vsix:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Robert923/vscode-start-git-bash/c594576c35104c3bc2a9d9b4d62bc2eecd8a4da1/start-git-bash-1.0.0.vsix
--------------------------------------------------------------------------------
/test/extension.test.ts:
--------------------------------------------------------------------------------
1 | //
2 | // Note: This example test is leveraging the Mocha test framework.
3 | // Please refer to their documentation on https://mochajs.org/ for help.
4 | //
5 |
6 | // The module 'assert' provides assertion methods from node
7 | import * as assert from 'assert';
8 |
9 | // You can import and use all API from the 'vscode' module
10 | // as well as import your extension to test it
11 | import * as vscode from 'vscode';
12 | import * as myExtension from '../src/extension';
13 |
14 | // Defines a Mocha test suite to group tests of similar kind together
15 | suite("Extension Tests", () => {
16 |
17 | // Defines a Mocha unit test
18 | test("Something 1", () => {
19 | assert.equal(-1, [1, 2, 3].indexOf(5));
20 | assert.equal(-1, [1, 2, 3].indexOf(0));
21 | });
22 | });
--------------------------------------------------------------------------------
/test/index.ts:
--------------------------------------------------------------------------------
1 | //
2 | // PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
3 | //
4 | // This file is providing the test runner to use when running extension tests.
5 | // By default the test runner in use is Mocha based.
6 | //
7 | // You can provide your own test runner if you want to override it by exporting
8 | // a function run(testRoot: string, clb: (error:Error) => void) that the extension
9 | // host can call to run the tests. The test runner is expected to use console.log
10 | // to report the results back to the caller. When the tests are finished, return
11 | // a possible error to the callback or null if none.
12 |
13 | var testRunner = require('vscode/lib/testrunner');
14 |
15 | // You can directly control Mocha options by uncommenting the following lines
16 | // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
17 | testRunner.configure({
18 | ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
19 | useColors: true // colored output from test results
20 | });
21 |
22 | module.exports = testRunner;
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "target": "es5",
5 | "outDir": "out",
6 | "noLib": true,
7 | "sourceMap": true,
8 | "rootDir": "."
9 | },
10 | "exclude": [
11 | "node_modules"
12 | ]
13 | }
--------------------------------------------------------------------------------
/typings/node.d.ts:
--------------------------------------------------------------------------------
1 | ///
--------------------------------------------------------------------------------
/typings/vscode-typings.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------