├── .eslintrc.json ├── .gitignore ├── .travis.yml ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── .vscodeignore ├── LICENSE.txt ├── README.md ├── assets ├── cp.png ├── gi.gif ├── icon-64x64.png ├── icon.png └── list.png ├── extension.js ├── jsconfig.json ├── package.json └── test ├── extension.test.js └── index.js /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": false, 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "parserOptions": { 9 | "ecmaFeatures": { 10 | "jsx": true 11 | }, 12 | "sourceType": "module" 13 | }, 14 | "rules": { 15 | "no-const-assign": "warn", 16 | "no-this-before-super": "warn", 17 | "no-undef": "warn", 18 | "no-unreachable": "warn", 19 | "no-unused-vars": "warn", 20 | "constructor-super": "warn", 21 | "valid-typeof": "warn" 22 | } 23 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Created by https://www.gitignore.io/api/node 4 | 5 | ### Node ### 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules 37 | jspm_packages 38 | 39 | # Optional npm cache directory 40 | .npm 41 | 42 | # Optional eslint cache 43 | .eslintcache 44 | 45 | # Optional REPL history 46 | .node_repl_history 47 | 48 | # Output of 'npm pack' 49 | *.tgz 50 | 51 | ### VisualStudioCode ### 52 | .vscode/* 53 | !.vscode/settings.json 54 | !.vscode/tasks.json 55 | !.vscode/launch.json 56 | 57 | ### VisualStudioCode ### 58 | .vscode-test/* 59 | .vscode/* 60 | !.vscode/settings.json 61 | !.vscode/tasks.json 62 | !.vscode/launch.json 63 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | dist: trusty 4 | 5 | language: node_js 6 | 7 | node_js: 8 | - "node" 9 | - "5" 10 | - "6" 11 | 12 | os: 13 | - osx 14 | - linux 15 | 16 | before_install: 17 | - if [ $TRAVIS_OS_NAME == "linux" ]; then 18 | export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0; 19 | sh -e /etc/init.d/xvfb start; 20 | sleep 3; 21 | fi 22 | 23 | install: 24 | - npm install 25 | 26 | script: 27 | - npm test --silent -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the extensions.json format 4 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that launches the extension inside a new window 2 | { 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "name": "Launch Extension", 7 | "type": "extensionHost", 8 | "request": "launch", 9 | "runtimeExecutable": "${execPath}", 10 | "args": [ 11 | "--extensionDevelopmentPath=${workspaceRoot}" 12 | ], 13 | "stopOnEntry": false 14 | }, 15 | { 16 | "name": "Launch Tests", 17 | "type": "extensionHost", 18 | "request": "launch", 19 | "runtimeExecutable": "${execPath}", 20 | "args": [ 21 | "--extensionDevelopmentPath=${workspaceRoot}", 22 | "--extensionTestsPath=${workspaceRoot}/test" 23 | ], 24 | "stopOnEntry": false 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version 4 | } -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | test/** 4 | .gitignore 5 | jsconfig.json 6 | vsc-extension-quickstart.md 7 | .eslintrc.json -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Hasit Mistry 4 | 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![vscode-icon](assets/icon-64x64.png) 2 | 3 | [![gi version](https://vsmarketplacebadge.apphb.com/version-short/rubbersheep.gi.svg)](https://marketplace.visualstudio.com/items?itemName=rubbersheep.gi) [![gi installs](https://vsmarketplacebadge.apphb.com/installs/rubbersheep.gi.svg)](https://marketplace.visualstudio.com/items?itemName=rubbersheep.gi) [![gi ratings](https://vsmarketplacebadge.apphb.com/rating-short/rubbersheep.gi.svg)](https://marketplace.visualstudio.com/items?itemName=rubbersheep.gi#review-details) 4 | 5 | [![Build Status](https://travis-ci.org/hasit/vscode-gi.svg?branch=master)](https://travis-ci.org/hasit/vscode-gi) 6 | 7 | `gi` stands for 'gitignore'. It is an extension for generating .gitignore files from inside Visual Studio Code. `gi` uses the [gitignore.io](https://www.gitignore.io) API to keep the list of operating systems, IDEs and programming languages updated. 8 | 9 | ![Usage of gi](assets/gi.gif) 10 | 11 | ## Install 12 | Press `Cmd+P` for MacOS and `Ctrl+P` for Linux/Windows to launch VS Code Quick Open, paste the following command, and press enter. 13 | 14 | ``` 15 | ext install gi 16 | ``` 17 | 18 | ## Usage 19 | 20 | Once you install and reload Visual Studio Code, you can run the extension by launching the Command Palette with `Shift+Cmd+P` for MacOS and `Shift+Ctrl+P` for Linux/Windows. Type in the following into the command palette. 21 | 22 | ``` 23 | gi 24 | ``` 25 | 26 | ![Launch gi from Command Palette](assets/cp.png) 27 | 28 | Once you press enter, `gi` will load a list of operating systems, IDEs, and programming lanuages. This might take a second so bear with it. 29 | 30 | ![List presented by gi](assets/list.png) 31 | 32 | You can search for (yay `showQuickPick()`!) the operating system, IDE, or programming lanuage you want to generate a .gitignore file for. Even though I would like you (the user) to be able to pick multiple items from the list, it is currenly not supported by [vscode namespace API](https://code.visualstudio.com/docs/extensionAPI/vscode-api). I have put in a feature request [here](https://github.com/Microsoft/vscode/issues/12925), but it seems that it has been on the todo list for quite some time now [here](https://github.com/Microsoft/vscode/issues/238). 33 | 34 | `gi` will show the result of your actions in two places depending on importance. 35 | 1. InformationMessage - InformationMessage is the toast that slides down and requires an action from you. High level details such as '.gitignore created' are shown here. 36 | 2. StatusBarMessage - Status bar (View -> Toggle Status Bar) is at the bottom of the window. Low level details such as 'You picked node.' are shown here. 37 | 38 | At any moment you can press the `Escape - ` key to stop `gi`. 39 | 40 | ## Todo 41 | 42 | - Add tests. 43 | - Add multi-select support to list. 44 | 45 | ## Contributing 46 | 47 | This is my very first extension for Visual Studio Code. If you find the code to be bug ridden, with mistakes or just plain old amazing, send in a word. You are welcome to comment/ask questions/post issues/send PRs on the [Github page](https://github.com/hasit/vscode-gi). 48 | 49 | ## Note 50 | 51 | `gi` uses the API exposed by [gitignore.io](https://www.gitignore.io). I made this extension as a learning experience. 52 | 53 | I would like to thank [Joe Blau](https://joeblau.com) for this work on [gitignore.io](https://www.gitignore.io)'s API and [Jason Long](http://www.jasonlong.me) for his help with creating the awesome icon used by `gi`. 54 | 55 | -------------------------------------------------------------------------------- /assets/cp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasit/vscode-gi/318aab3cb4578872ba4e42f5131f384924adaf52/assets/cp.png -------------------------------------------------------------------------------- /assets/gi.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasit/vscode-gi/318aab3cb4578872ba4e42f5131f384924adaf52/assets/gi.gif -------------------------------------------------------------------------------- /assets/icon-64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasit/vscode-gi/318aab3cb4578872ba4e42f5131f384924adaf52/assets/icon-64x64.png -------------------------------------------------------------------------------- /assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasit/vscode-gi/318aab3cb4578872ba4e42f5131f384924adaf52/assets/icon.png -------------------------------------------------------------------------------- /assets/list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hasit/vscode-gi/318aab3cb4578872ba4e42f5131f384924adaf52/assets/list.png -------------------------------------------------------------------------------- /extension.js: -------------------------------------------------------------------------------- 1 | /* jshint esversion: 6 */ 2 | var fs = require('fs'); 3 | var path = require('path'); 4 | 5 | var vscode = require('vscode'); 6 | var axios = require('axios'); 7 | var errorEx = require('error-ex'); 8 | 9 | function activate(context) { 10 | console.log('Extension "gi" is now active!'); 11 | 12 | var disposable = vscode.commands.registerCommand('extension.gi', function () { 13 | var giURL = 'https://www.gitignore.io/api/'; 14 | var giError = new errorEx('giError'); 15 | 16 | axios.get(giURL + 'list') 17 | .then(function (response) { 18 | var rawList = response.data; 19 | rawList = rawList.replace(/(\r\n|\n|\r)/gm, ","); 20 | var formattedList = rawList.split(','); 21 | 22 | const options = { 23 | ignoreFocusOut: false, 24 | placeHolder: 'Search Operating Systems, IDEs, or Programming Languages', 25 | }; 26 | 27 | vscode.window.showQuickPick(formattedList, options) 28 | .then(function (val) { 29 | if (val === undefined) { 30 | vscode.window.setStatusBarMessage('gi escaped', 3000); 31 | var err = new giError('EscapeException'); 32 | throw err; 33 | } 34 | vscode.window.setStatusBarMessage('You picked ' + val, 3000); 35 | axios.get(giURL + val) 36 | .then(function (response) { 37 | makeFile(response.data); 38 | }) 39 | .catch(function (err) { 40 | console.log(err); 41 | }); 42 | }); 43 | 44 | function makeFile(content) { 45 | const choices = [{ 46 | label: 'Append', 47 | description: 'Append to current .gitignore' 48 | }, { 49 | label: 'Overwrite', 50 | description: `Overwrite current .gitignore` 51 | }]; 52 | 53 | const options = { 54 | matchOnDescription: true, 55 | placeHolder: "A .gitignore file already exists in your current working directory. What would you like to do?" 56 | }; 57 | 58 | var giFile = path.join(vscode.workspace.rootPath, '.gitignore'); 59 | 60 | fs.access(giFile, fs.F_OK, function (err) { 61 | if (!err) { 62 | console.log('.gitignore already exists'); 63 | vscode.window.showQuickPick(choices, options) 64 | .then(function (val) { 65 | if (!val || val === undefined) { 66 | var err = new giError('EscapeException'); 67 | vscode.window.setStatusBarMessage('gi escaped', 3000); 68 | throw err; 69 | } 70 | if (val.label === 'Overwrite') { 71 | writeToFile(content, true); 72 | vscode.window.showInformationMessage('.gitignore overwritten'); 73 | return; 74 | } 75 | if (val.label === 'Append') { 76 | writeToFile(content, false); 77 | vscode.window.showInformationMessage('.gitignore appended'); 78 | return; 79 | } 80 | }); 81 | } else { 82 | console.log('.gitignore does not exist'); 83 | writeToFile(content, true); 84 | vscode.window.showInformationMessage('.gitignore created'); 85 | return; 86 | } 87 | }); 88 | 89 | function writeToFile(content, flag) { 90 | if (flag === true) { 91 | fs.writeFileSync(giFile, content, 'utf-8', function (err) { 92 | if (err) { 93 | console.log('Failed to write to .gitignore'); 94 | } else { 95 | console.log('.gitignore created'); 96 | } 97 | }); 98 | } else { 99 | fs.appendFileSync(giFile, content, 'utf-8', function (err) { 100 | if (err) { 101 | console.log('Failed to append to .gitignore'); 102 | } else { 103 | console.log('.gitignore appended'); 104 | } 105 | }); 106 | } 107 | } 108 | } 109 | }) 110 | .catch(function (err) { 111 | console.log(err); 112 | }); 113 | }); 114 | 115 | context.subscriptions.push(disposable); 116 | } 117 | exports.activate = activate; 118 | 119 | function deactivate() {} 120 | exports.deactivate = deactivate; -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "lib": [ 6 | "es6" 7 | ] 8 | }, 9 | "exclude": [ 10 | "node_modules" 11 | ] 12 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gi", 3 | "displayName": "gi", 4 | "description": "Generating .gitignore files made easy", 5 | "version": "0.2.11", 6 | "publisher": "rubbersheep", 7 | "license": "MIT", 8 | "icon": "assets/icon.png", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/hasit/vscode-gi" 12 | }, 13 | "homepage": "https://github.com/hasit/vscode-gi/blob/master/README.md", 14 | "bugs": { 15 | "url": "https://github.com/hasit/vscode-gi/issues" 16 | }, 17 | "engines": { 18 | "vscode": "^1.5.0" 19 | }, 20 | "categories": [ 21 | "Other" 22 | ], 23 | "activationEvents": [ 24 | "onCommand:extension.gi" 25 | ], 26 | "main": "./extension", 27 | "contributes": { 28 | "commands": [ 29 | { 30 | "command": "extension.gi", 31 | "title": "gi" 32 | } 33 | ] 34 | }, 35 | "scripts": { 36 | "test": "node ./node_modules/vscode/bin/test", 37 | "postinstall": "node ./node_modules/vscode/bin/install" 38 | }, 39 | "devDependencies": { 40 | "typescript": "^2.0.3", 41 | "vscode": "^1.0.0", 42 | "mocha": "^3.1.2", 43 | "eslint": "^3.6.0", 44 | "@types/node": "^6.0.40", 45 | "@types/mocha": "^2.2.32" 46 | }, 47 | "dependencies": { 48 | "axios": "^0.15.2", 49 | "error-ex": "^1.3.0" 50 | } 51 | } -------------------------------------------------------------------------------- /test/extension.test.js: -------------------------------------------------------------------------------- 1 | /* global suite, test */ 2 | 3 | // 4 | // Note: This example test is leveraging the Mocha test framework. 5 | // Please refer to their documentation on https://mochajs.org/ for help. 6 | // 7 | 8 | // The module 'assert' provides assertion methods from node 9 | var assert = require('assert'); 10 | 11 | // You can import and use all API from the 'vscode' module 12 | // as well as import your extension to test it 13 | var vscode = require('vscode'); 14 | var myExtension = require('../extension'); 15 | 16 | // Defines a Mocha test suite to group tests of similar kind together 17 | suite("Extension Tests", function() { 18 | // Defines a Mocha unit test 19 | test("Something 1", function() { 20 | assert.equal(-1, [1, 2, 3].indexOf(5)); 21 | assert.equal(-1, [1, 2, 3].indexOf(0)); 22 | }); 23 | }); -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 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.js (suite, test, etc.) 19 | useColors: true // colored output from test results 20 | }); 21 | 22 | module.exports = testRunner; --------------------------------------------------------------------------------