[
  {
    "path": ".editorconfig",
    "content": "[*]\nend_of_line = lf\n\n[*.js]\ncharset = utf-8\nindent_style = space\nindent_size = 2"
  },
  {
    "path": ".gitignore",
    "content": "node_modules\n*.swp\n"
  },
  {
    "path": ".jscsrc",
    "content": "{\n    \"excludeFiles\": [\n        \"node_modules/**\"\n    ],\n\n    \"disallowEmptyBlocks\": true,\n\n    \"disallowImplicitTypeConversion\": [\"numeric\", \"boolean\", \"binary\", \"string\"],\n\n    \"disallowKeywords\": [\"with\"],\n\n    \"disallowKeywordsOnNewLine\": [\"else\", \"catch\", \"finally\"],\n\n    \"disallowMixedSpacesAndTabs\": true,\n\n    \"disallowMultipleLineStrings\": true,\n\n    \"disallowNewlineBeforeBlockStatements\": true,\n\n    \"disallowOperatorBeforeLineBreak\": [\".\"],\n\n    \"disallowPaddingNewlinesInBlocks\": true,\n\n    \"disallowQuotedKeysInObjects\": \"allButReserved\",\n\n    \"disallowSpaceAfterObjectKeys\": true,\n\n    \"disallowSpaceAfterPrefixUnaryOperators\": [\"++\", \"--\", \"+\", \"-\", \"~\", \"!\"],\n\n    \"disallowSpaceBeforePostfixUnaryOperators\": [\"++\", \"--\"],\n\n    \"disallowSpacesInCallExpression\": true,\n\n    \"disallowSpacesInFunction\": {\n        \"beforeOpeningRoundBrace\": true\n    },\n\n    \"disallowSpacesInFunctionDeclaration\": {\n        \"beforeOpeningRoundBrace\": true\n    },\n\n    \"disallowSpacesInFunctionExpression\": {\n        \"beforeOpeningRoundBrace\": true\n    },\n\n    \"disallowSpacesInNamedFunctionExpression\": {\n        \"beforeOpeningRoundBrace\": true\n    },\n\n    \"disallowSpacesInsideArrayBrackets\": \"all\",\n\n    \"disallowSpacesInsideParentheses\": true,\n\n    \"disallowTrailingComma\": true,\n\n    \"disallowTrailingWhitespace\": true,\n\n    \"disallowYodaConditions\": true,\n\n    \"requireBlocksOnNewline\": true,\n\n    \"requireCamelCaseOrUpperCaseIdentifiers\": true,\n\n    \"requireCapitalizedConstructors\": true,\n\n    \"requireCommaBeforeLineBreak\": true,\n\n    \"requireCurlyBraces\": [\n        \"if\",\n        \"else\",\n        \"for\",\n        \"while\",\n        \"do\",\n        \"try\",\n        \"catch\",\n        \"finally\"\n    ],\n\n    \"requireDotNotation\": true,\n\n    \"requireKeywordsOnNewLine\": [\n        \"return\",\n        \"for\",\n        \"try\",\n        \"do\",\n        \"switch\",\n        \"case\"\n    ],\n\n    \"requireLineBreakAfterVariableAssignment\": true,\n\n    \"requireLineFeedAtFileEnd\": true,\n\n    \"disallowMultipleVarDecl\": true,\n\n    \"requireOperatorBeforeLineBreak\": [\n        \"=\",\n        \"+\",\n        \"-\",\n        \"/\",\n        \"*\",\n        \"==\",\n        \"===\",\n        \"!=\",\n        \"!==\",\n        \">\",\n        \">=\",\n        \"<\",\n        \"<=\"\n    ],\n\n    \"requireParenthesesAroundIIFE\": true,\n\n    \"requireSpaceAfterBinaryOperators\": [\n        \"=\",\n        \",\",\n        \"+\",\n        \"-\",\n        \"/\",\n        \"*\",\n        \"==\",\n        \"===\",\n        \"!=\",\n        \"!==\",\n        \"<\",\n        \">\",\n        \"<=\",\n        \">=\",\n        \"%\"\n    ],\n\n    \"requireSpaceAfterKeywords\": [\n        \"if\",\n        \"else\",\n        \"for\",\n        \"while\",\n        \"do\",\n        \"switch\",\n        \"case\",\n        \"return\",\n        \"try\",\n        \"catch\",\n        \"finally\",\n        \"typeof\"\n    ],\n\n    \"requireSpaceAfterLineComment\": true,\n\n    \"requireSpaceBeforeBinaryOperators\": [\n        \"=\",\n        \"+\",\n        \"-\",\n        \"/\",\n        \"*\",\n        \"==\",\n        \"===\",\n        \"!=\",\n        \"!==\",\n        \"<\",\n        \">\",\n        \"<=\",\n        \">=\",\n        \"%\"\n    ],\n\n    \"requireSpaceBeforeBlockStatements\": true,\n\n    \"requireSpaceBeforeKeywords\": [\n        \"else\",\n        \"while\",\n        \"catch\",\n        \"finally\"\n    ],\n\n    \"requireSpaceBeforeObjectValues\": true,\n\n    \"requireSpaceBetweenArguments\": true,\n\n    \"requireSpacesInConditionalExpression\": {\n        \"afterTest\": true,\n        \"beforeConsequent\": true,\n        \"afterConsequent\": true,\n        \"beforeAlternate\": true\n    },\n\n    \"requireSpacesInForStatement\": true,\n\n    \"requireSpacesInFunction\": {\n        \"beforeOpeningCurlyBrace\": true\n    },\n\n    \"requireSpacesInFunctionDeclaration\": {\n        \"beforeOpeningCurlyBrace\": true\n    },\n\n    \"requireSpacesInFunctionExpression\": {\n        \"beforeOpeningCurlyBrace\": true\n    },\n\n    \"requireSpacesInNamedFunctionExpression\": {\n        \"beforeOpeningCurlyBrace\": true\n    },\n\n    \"requireSemicolons\": true,\n\n    \"requireSpacesInsideObjectBrackets\": \"all\",\n\n    \"validateIndentation\": 2,\n\n    \"validateLineBreaks\": \"LF\",\n\n    \"validateParameterSeparator\": \", \",\n\n    \"validateQuoteMarks\": { \"mark\": \"'\", \"escape\": true }\n}\n"
  },
  {
    "path": ".npmingnore",
    "content": "node_modules\n"
  },
  {
    "path": "HISTORY.md",
    "content": "## 2.2.0 (March 22, 2017)\n\n- Fixed passing settings to `open()` when only `cmd` option is set (#10)\n- Changed behaviour to use an editor settings as defaults when `editor` and `cmd` options are specified\n- Added `--pattern` option to CLI\n\n## 2.1.0 (March 21, 2017)\n\n- Added basic support for `emacs` (thanks to @zefirka)\n- Fixed crash on attempt to use `vim` on non-`darwin` platform\n\n## 2.0.0 (March 15, 2017)\n\n- Added basic support for `vim` (thanks to @pofigizm)\n- Added support for `Visual Studio` (thanks to @generalov)\n- Changed node.js support to `0.12` and greater\n\n## 1.2.1 (November 14, 2016)\n\n- Added support for `Visual Studio Code`\n\n## 1.2.0 (November 12, 2015)\n\n- Added support for JetBrains's IDEs on Windows (thanks to @Mavrin)\n\n## 1.1.0 (November 8, 2015)\n\n- Added support for `WebStorm` (thanks to @chicoxyzzy)\n- Added support for `IDEA 14 CE` (thanks to @chicoxyzzy)\n- Added support for `PhpStorm` (thanks to @silentroach)\n- Removed `preferGlobal` option from `package.json`\n- Improved documentation\n\n## 1.0 (September 24, 2015)\n\n- Initial release\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2015 Roman Dvornov\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n"
  },
  {
    "path": "README.md",
    "content": "[![NPM version](https://img.shields.io/npm/v/open-in-editor.svg)](https://www.npmjs.com/package/open-in-editor)\n\nNPM package to open a file in editor.\n\nSupported editors:\n\n- [Sublime Text](http://www.sublimetext.com/)\n- [Atom Editor](https://atom.io/)\n- [Visual Studio Code](https://code.visualstudio.com/)\n- [WebStorm](https://www.jetbrains.com/webstorm/)\n- [PhpStorm](https://www.jetbrains.com/phpstorm/)\n- [IDEA 14 Community Edition](https://www.jetbrains.com/idea/download/)\n- [Vim](http://www.vim.org/)\n- [Emacs](https://www.gnu.org/software/emacs/)\n- [Visual Studio](https://www.visualstudio.com/)\n\nYou also can use any other editor that is able to open files from command line.\n\n## Installation\n\n```\nnpm install open-in-editor\n```\n\n## Usage\n\nFirst of all you should create an interface with your settings.\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  // options\n}, function(err) {\n  console.error('Something went wrong: ' + err);\n});\n```\n\nResulting object has a single method `open`. This method runs terminal command that opens an editor. Result of this method is a promise:\n\n```js\neditor.open('path/to/file.js:3:10')\n  .then(function() {\n    console.log('Success!');\n  }, function(err) {\n    console.error('Something went wrong: ' + err);\n  });\n```\n\n## API\n\n```\nopenInEditor.configure([options][, failCallback]);\n```\n\nArguments:\n\n- `options` – *optional* is used to set up a command to launch an editor. If no options set it will try to get the command from [environment](#environment)\n- `failCallback` – *optional* function that is called when something's wrong with editor setup.\n\nIf editor setup was successful `configure` method returns an interface with single method `open`. The method accepts file reference with the following format: `filename[:line[:column]]`, where `line` and `column` tell the editor where to place cursor when file is opened.\n\n### Options\n\n#### editor\n\nType: `String` or `null`  \nValues: `'sublime'`, `'atom'`, `'code'`, `'webstorm'`, `'phpstorm'`, `'idea14ce'`, `'vim'`, `'emacs'`, `'visualstudio'`  \nDefault: `null`\n\nEditor to open a file. Once value is set, we try to detect a command to launch an editor.\n\nSupported editors:\n\n- `sublime` – Sublime Text\n- `atom` – Atom Editor\n- `code` – Visual Studio Code\n- `webstorm` – WebStorm\n- `phpstorm` - PhpStorm\n- `idea14ce` – IDEA 14 CE\n- `vim` – Vim (via Terminal, Mac OS only)\n- `emacs` – Emacs (via Terminal, Mac OS only)\n- `visualstudio` – Visual Studio\n\n#### cmd\n\nType: `String` or `null`  \nDefault: `null`\n\nCommand to launch an editor.\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  cmd: '/path/to/editor/app'\n});\n```\n\nIf `editor` option is also set, an editor settings are using as default settings.\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  editor: 'code',\n  cmd: '/path/to/editor/app' // will be called as '/path/to/editor/app -r -g {filename}:{line}:{column}'\n});\n```\n\n#### pattern\n\nType: `String` or `null`  \nDefault: `null`\n\nOption to specify arguments for a command. Pattern can contain placeholders to be replaced by actual values. Supported placeholders: `filename`, `line` and `column`.\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  cmd: 'code',\n  pattern: '-r -g {filename}:{line}:{column}'\n});\n```\n\nIf there's no `{filename}` placeholder in the command then `{filename}:{line}:{column}` is appended. That way previous example can be simplified:\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  cmd: 'code',\n  pattern: '-r -g' // the same as '-r -g {filename}:{line}:{column}'\n});\n```\n\n#### line\n\nType: `Number`  \nDefault: `1`\n\nDefines the number of the first line in the editor. Usually it's `1`, but you can set it to `0`.\n\n#### column\n\nType: `Number`  \nDefault: `1`\n\nDefines the number of the first column in the editor. Usually it's `1`, but you can set it to `0`.\n\n\n## Environment\n\nIf no `editor` or `cmd` option is specified, we try to get the command to launch an editor using environment settings. Following values can be used (in descending priority):\n\n- `process.env.OPEN_FILE`\n- `process.env.VISUAL`\n- `process.env.EDITOR`\n\nFirst value found is used. If it's `process.env.VISUAL` or `process.env.EDITOR`, it's used directly as `cmd` option. But `process.env.OPEN_FILE` is different: if value is a valid for `editor` option, it's used for it, otherwise it's used as a value for `cmd` option.\n\nYou can set env settings per command:\n\n```\nOPEN_FILE=atom oe path/to/file.js:4:15\nOPEN_FILE=\"code -r -g\" node script.js\n```\n\n## CLI\n\nPackage could be installed globally.\n\n```\nnpm install open-in-editor -g\n```\n\nIn this case `oe` command will be available in terminal.\n\n```\nUsage:\n\n  oe [filename] [options]\n\nOptions:\n\n      --cmd <command>      Command to open file\n      --debug              Debug errors\n  -e, --editor <editor>    Editor: atom, code, sublime, webstorm, phpstorm, idea14ce, vim, visualstudio, emacs\n  -f, --file <filename>    File to open\n  -h, --help               Output usage information\n  -p, --pattern <pattern>  Filename pattern and args, i.e. something going after cmd\n  -v, --version            Output the version\n```\n\n## Related projects\n\n- [express-open-in-editor](https://github.com/lahmatiy/express-open-in-editor) – `Express` extension to open files from browser.\n- [babel-plugin-source-wrapper](https://github.com/restrry/babel-plugin-source-wrapper) – `Babel` plugin that instruments source code to associate objects with location they defined in code base.\n- [Component Inspector](https://github.com/lahmatiy/component-inspector) – developer tool to inspect components that can open component creation source location in editor. Has integrations for `React`, `Backbone` and can be adopted for other frameworks.\n\n## License\n\nMIT\n"
  },
  {
    "path": "bin/oe",
    "content": "#!/usr/bin/env node\n\nvar clap = require('clap');\nvar version = require('../package.json').version;\nvar editors = require('../lib/editors');\nvar fail = require('../lib/utils').fail;\nvar main = require('../lib/index');\n\nvar command = clap.create('oe', '[filename]')\n  .description('Open file in editor')\n  .version(version)\n\n  .option('-f, --file <filename>', 'File to open')\n  .option('-e, --editor <editor>', 'Editor: ' + Object.keys(editors).join(', '))\n  .option('-p, --pattern <pattern>', 'Filename pattern and args, i.e. something going after cmd')\n  .option('--cmd <command>', 'Command to open file')\n  .option('--debug', 'Debug errors')\n\n  .action(function(args) {\n    main\n      .configure(this.values, fail)\n      .open(this.values.file || args[0])\n      .catch(function(err) {\n        if (this.values.debug) {\n          process.nextTick(function() {\n            throw err;\n          });\n        } else {\n          fail(err);\n        }\n      }.bind(this));\n  });\n\ntry {\n  command.run();\n} catch (err) {\n  if (err instanceof clap.Error == false) {\n    throw err;\n  }\n\n  fail(err);\n}\n"
  },
  {
    "path": "lib/check.js",
    "content": "var exec = require('child_process').exec;\nvar fs = require('fs');\nvar quote = require('./utils').quote;\n\nfunction checkCommand(cmd, name, args) {\n  if (!args) {\n    return Promise.reject('No args to check command: ' + cmd);\n  }\n\n  return new Promise(function(resolve, reject) {\n    exec(cmd + ' ' + args, function(err, output) {\n      if (err || output.indexOf(name) !== 0) {\n        reject(err);\n      } else {\n        resolve(cmd);\n      }\n    });\n  });\n}\n\nfunction checkPath(path, name) {\n  if (!fs.existsSync(path)) {\n    return Promise.reject('Path does not exist: ' + path);\n  }\n\n  return Promise.resolve(path);\n}\n\nmodule.exports = {\n  command: checkCommand,\n  path: checkPath\n};\n"
  },
  {
    "path": "lib/detect.js",
    "content": "var check = require('./check');\nvar any = require('./utils').any;\n\nfunction detect(name, commands, args, locations) {\n  function run(task) {\n    return this(task, name, args);\n  }\n\n  locations = locations[process.platform] || [];\n\n  return any(\n    [].concat(\n      commands.map(run, check.command),\n      locations.map(run, check.path)\n    ),\n    'Not detected'\n  );\n}\n\nmodule.exports = detect;\nmodule.exports.lazy = function(name, commands, args, locations) {\n  var memo;\n\n  return function() {\n    if (!memo) {\n      memo = detect(name, commands, args, locations);\n    }\n\n    return memo;\n  };\n};\nmodule.exports.platformSupport = function(platforms, editor, resolveValue) {\n  return function() {\n    // we use only system parts so we haven't to check anything except os\n    if (platforms.indexOf(process.platform) !== -1) {\n      return Promise.resolve(resolveValue);\n    }\n\n    return Promise.reject('\"Open in ' + editor + '\" does not implemented for your platform (' + process.platform + ')');\n  };\n};\n"
  },
  {
    "path": "lib/editors/atom.js",
    "content": "var atHomeDir = require('../utils').atHomeDir;\n\nvar settings = {\n  pattern: '{filename}:{line}:{column}'\n};\n\nvar detect = require('../detect').lazy('Atom Editor', ['atom'], '-h', {\n  darwin: [\n    '/Applications/Atom.app/Contents/Resources/app/atom.sh'\n  ],\n  win32: [\n    atHomeDir('AppData/Local/atom/bin/atom.cmd')\n  ]\n});\n\nvar open = require('../open').detectAndOpenFactory(detect, settings);\n\nmodule.exports = {\n  settings: settings,\n  detect: detect,\n  open: open\n};\n"
  },
  {
    "path": "lib/editors/code.js",
    "content": "var atHomeDir = require('../utils').atHomeDir;\n\nvar settings = {\n  pattern: '-r -g {filename}:{line}:{column}'\n};\n\nvar detect = require('../detect').lazy('Visual Studio Code', ['code'], '-h', {\n  darwin: [\n    '/Applications/Visual Studio Code.app/Contents/MacOS/Electron'\n  ],\n  win32: [\n    'C:/Program Files/Microsoft VS Code/bin/code.cmd',\n    'C:/Program Files (x86)/Microsoft VS Code/bin/code.cmd',\n    atHomeDir('AppData/Local/Code/bin/code.cmd')\n  ]\n});\n\nvar open = require('../open').detectAndOpenFactory(detect, settings);\n\nmodule.exports = {\n  settings: settings,\n  detect: detect,\n  open: open\n};\n"
  },
  {
    "path": "lib/editors/common/jetbrains.js",
    "content": "var fs = require('fs');\nvar path = require('path');\nvar lazyDetect = require('../../detect').lazy;\n\nvar settings = {\n  pattern: '{projectPath} --line {line} {filename}'\n};\n\nvar winDirs = (function() {\n  var jetbrainsFolder = 'c:/Program Files (x86)/JetBrains/';\n\n  if (!fs.existsSync(jetbrainsFolder)) {\n    return [];\n  }\n\n  return fs.readdirSync(jetbrainsFolder)\n    .map(function(name) {\n      return path.join(jetbrainsFolder, name);\n    })\n    .filter(function(path) {\n      return fs.statSync(path).isDirectory();\n    });\n})();\n\nmodule.exports = function(config) {\n  var detect = lazyDetect(config.name, [], '', {\n    darwin: [\n      '/Applications/' + config.appFolder + '.app/Contents/MacOS/' + config.executable\n    ],\n    win32: winDirs.map(function(dir) {\n      return dir + '/bin/' + config.executable + '.exe';\n    })\n  });\n  var open = require('../../open').detectAndOpenFactory(detect, settings);\n\n  return {\n    settings: settings,\n    detect: detect,\n    open: open\n  };\n};\n"
  },
  {
    "path": "lib/editors/common/terminal.js",
    "content": "var osascript = function(script) {\n  return 'osascript -e \\'' + script + '\\'';\n};\n\nvar terminal = function(cmd) {\n  return 'tell application \"Terminal\" to do script \"' + cmd + '\"';\n};\n\nvar runInTerminal = function(cmd) {\n  return osascript(terminal('cd {projectPath}; ' + cmd));\n};\n\nmodule.exports = runInTerminal;\n"
  },
  {
    "path": "lib/editors/emacs.js",
    "content": "var runInTerminal = require('./common/terminal');\n\nvar settings = {\n  patternOnly: true,\n  escapeQuotes: true,\n  pattern: runInTerminal('emacs --no-splash \\\\\"+{line}:{column}\\\\\" {filename}')\n};\n\nvar detect = require('../detect').platformSupport(['darwin'], 'vim');\nvar open = require('../open').detectAndOpenFactory(detect, settings);\n\nmodule.exports = {\n  settings: settings,\n  detect: detect,\n  open: open\n};\n"
  },
  {
    "path": "lib/editors/idea14ce.js",
    "content": "var jetbrainsEditor = require('./common/jetbrains');\n\nmodule.exports = jetbrainsEditor({\n  name: 'IDEA 14 CE',\n  appFolder: 'IntelliJ IDEA 14 CE',\n  executable: 'idea'\n});\n"
  },
  {
    "path": "lib/editors/index.js",
    "content": "module.exports = {\n  atom: require('./atom'),\n  code: require('./code'),\n  sublime: require('./sublime'),\n  webstorm: require('./webstorm'),\n  phpstorm: require('./phpstorm'),\n  idea14ce: require('./idea14ce'),\n  vim: require('./vim'),\n  visualstudio: require('./visualstudio'),\n  emacs: require('./emacs')\n};\n"
  },
  {
    "path": "lib/editors/phpstorm.js",
    "content": "var jetbrainsEditor = require('./common/jetbrains');\n\nmodule.exports = jetbrainsEditor({\n  name: 'PhpStorm IDE',\n  appFolder: 'PhpStorm',\n  executable: 'phpstorm'\n});\n"
  },
  {
    "path": "lib/editors/sublime.js",
    "content": "var settings = {\n  pattern: '{filename}:{line}:{column}'\n};\n\nvar detect = require('../detect').lazy('Sublime Text', ['subl'], '-h', {\n  darwin: [\n    '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'\n  ],\n  win32: [\n    'C:/Program Files/Sublime Text/subl.exe',\n    'C:/Program Files/Sublime Text 2/subl.exe',\n    'C:/Program Files/Sublime Text 3/subl.exe',\n    'C:/Program Files (x86)/Sublime Text/subl.exe',\n    'C:/Program Files (x86)/Sublime Text 2/subl.exe',\n    'C:/Program Files (x86)/Sublime Text 3/subl.exe'\n  ]\n});\n\nvar open = require('../open').detectAndOpenFactory(detect, settings);\n\nmodule.exports = {\n  settings: settings,\n  detect: detect,\n  open: open\n};\n"
  },
  {
    "path": "lib/editors/vim.js",
    "content": "var runInTerminal = require('./common/terminal');\n\nvar settings = {\n  patternOnly: true,\n  escapeQuotes: true,\n  pattern: runInTerminal('vim {filename} \\\\\"+call cursor({line}, {column})\\\\\"')\n};\n\nvar detect = require('../detect').platformSupport(['darwin'], 'vim');\nvar open = require('../open').detectAndOpenFactory(detect, settings);\n\nmodule.exports = {\n  settings: settings,\n  detect: detect,\n  open: open\n};\n"
  },
  {
    "path": "lib/editors/visualstudio.js",
    "content": "var path = require('path');\nvar helperPath = path.resolve(__dirname, 'visualstudio.vbs');\n\nvar settings = {\n  pattern: '{filename} {line} {column}'\n};\n\nvar detect = require('../detect').platformSupport(['win32'], 'Visual Studio', helperPath);\nvar open = require('../open').detectAndOpenFactory(detect, settings);\n\nmodule.exports = {\n  settings: settings,\n  detect: detect,\n  open: open\n};\n"
  },
  {
    "path": "lib/editors/visualstudio.vbs",
    "content": "' Copyright (c) 2016, Evgeny Panasyuk\n\n' Permission is hereby granted, free of charge, to any person or organization\n' obtaining a copy of the software and accompanying documentation covered by\n' this license (the \"Software\") to use, reproduce, display, distribute,\n' execute, and transmit the Software, and to prepare derivative works of the\n' Software, and to permit third-parties to whom the Software is furnished to\n' do so, all subject to the following:\n' \n' The copyright notices in the Software and this entire statement, including\n' the above license grant, this restriction and the following disclaimer,\n' must be included in all copies of the Software, in whole or in part, and\n' all derivative works of the Software, unless such copies or derivative\n' works are solely in the form of machine-executable object code generated by\n' a source language processor.\n' \n' THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n' FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT\n' SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE\n' FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,\n' ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n' DEALINGS IN THE SOFTWARE.\n\n' e-mail: E?????[dot]P???????[at]gmail.???\n\nOption Explicit\n\nDim filename, line, column\nDim MSVS_versions, version\nDim dte, fso, wshShell\nDim fullpath\n\nfilename = WScript.Arguments(0)\nline = WScript.Arguments(1)\ncolumn = WScript.Arguments(2)\n\nMSVS_versions = Array _\n( _\n    \"VisualStudio.DTE.7\", _\n    \"VisualStudio.DTE.7.1\", _\n    \"VisualStudio.DTE.8.0\", _\n    \"VisualStudio.DTE.9.0\", _\n    \"VisualStudio.DTE.10.0\", _\n    \"VisualStudio.DTE.11.0\", _\n    \"VisualStudio.DTE.12.0\", _\n    \"VisualStudio.DTE.14.0\", _\n    \"VisualStudio.DTE.15.0\" _\n)\n\nOn Error Resume Next\n\nFor each version in MSVS_versions\n    Err.Clear\n    Set dte = getObject(,version)\n    If Err.Number = 0 Then\n        Exit For\n    End If\nNext\n\nIf Err.Number <> 0 Then\n    Set dte = WScript.CreateObject(\"VisualStudio.DTE\")\n    Err.Clear\nEnd If\n\nSet wshShell = WScript.CreateObject(\"WScript.Shell\")\nSet fso = WScript.CreateObject(\"Scripting.FileSystemObject\")\nfullpath = fso.GetAbsolutePathName(filename)\n\ndte.MainWindow.Activate()\ndte.MainWindow.Visible = True\ndte.UserControl = True\nwshShell.AppActivate dte.MainWindow.Caption\n\ndte.ItemOperations.OpenFile fullpath\ndte.ActiveDocument.Selection.MoveToLineAndOffset line, column + 1\n\nif Err.Number <> 0 Then\n    WScript.Quit Err.Number\nEnd If\n\nOn Error Goto 0\n"
  },
  {
    "path": "lib/editors/webstorm.js",
    "content": "var jetbrainsEditor = require('./common/jetbrains');\n\nmodule.exports = jetbrainsEditor({\n  name: 'WebStorm IDE',\n  appFolder: 'WebStorm',\n  executable: 'webstorm'\n});\n"
  },
  {
    "path": "lib/index.js",
    "content": "var extractFilename = require('./utils').extractFilename;\nvar number = require('./utils').number;\nvar assign = require('./utils').assign;\nvar editors = require('./editors');\nvar openFactory = require('./open').factory;\n\nmodule.exports = {\n  configure: function(options, cb) {\n    options = options || {};\n    cb = cb || function() {};\n\n    var sourceLineOffset = number(options.line, 1);\n    var sourceColumnOffset = number(options.column, 1);\n    var editor = options.editor;\n    var cmd = options.cmd;\n    var open;\n\n    if (!cmd && !editor) {\n      if (editors.hasOwnProperty(process.env.OPEN_FILE)) {\n        editor = process.env.OPEN_FILE;\n      } else {\n        cmd = process.env.OPEN_FILE ||\n              process.env.VISUAL ||\n              process.env.EDITOR;\n      }\n    }\n\n    // if editor option is set then fail on wrong value\n    if (editor && !editors.hasOwnProperty(editor)) {\n      cb('Wrong value for `editor` option: ' + editor);\n      return;\n    }\n\n    if (cmd) {\n      var settings = {};\n\n      // use editor settings as base\n      if (editors.hasOwnProperty(editor)) {\n        assign(settings, editors[editor].settings);\n      }\n\n      open = openFactory(cmd, assign(settings, options));\n    } else {\n      if (!editor) {\n        cb('Editor is not specified');\n        return;\n      }\n\n      open = editors[editor].open;\n    }\n\n    return {\n      open: function(filename) {\n        if (!filename) {\n          return Promise.reject('File is not specified');\n        }\n\n        var info = extractFilename(filename);\n\n        return open([\n          info.filename,\n          Math.max(info.line - sourceLineOffset, 0),\n          Math.max(info.column - sourceColumnOffset, 0)\n        ].join(':'));\n      }\n    };\n  }\n};\n"
  },
  {
    "path": "lib/open.js",
    "content": "var exec = require('child_process').exec;\nvar number = require('./utils').number;\nvar quote = require('./utils').quote;\nvar extractFilename = require('./utils').extractFilename;\nvar append = require('./utils').append;\n\nfunction makeArguments(filename, settings) {\n  var info = extractFilename(filename);\n  var pattern = settings.pattern || '';\n  var values = {\n    projectPath: process.env.PROJECT_PATH || process.PWD || process.cwd(),\n    line: info.line + number(settings.line, 1),\n    column: info.column + number(settings.column, 1)\n  };\n\n  if (!/\\{filename\\}/.test(pattern)) {\n    pattern = append(pattern, '{filename}:{line}:{column}');\n  }\n\n  return pattern\n    .replace(\n      new RegExp('\\\\{(' + Object.keys(values).join('|') + ')\\\\}', 'g'),\n      function(m, name) {\n        return values[name];\n      }\n    )\n    // replace `{filename}` and adjoined right string for quoted filename,\n    // since filename can have spaces\n    //\n    //   {filename} --line 1 --column 2\n    //   => \"filename\" --line 1 --column 2\n    //\n    //   {filename}:1:2\n    //   => \"filename:1:2\"\n    //\n    .replace(/\\{filename\\}(\\S*)/, function(m, rest) {\n      return quote(info.filename + rest, settings.escapeQuotes);\n    });\n}\n\nfunction open(cmd, filename, settings) {\n  return new Promise(function(resolve, reject) {\n    var args;\n\n    settings = settings || {};\n    args = makeArguments(filename, settings);\n    cmd = settings.patternOnly ? args : append(quote(cmd), args);\n\n    exec(cmd, function(err) {\n      if (err) {\n        reject(err);\n      } else {\n        resolve();\n      }\n    });\n  });\n}\n\nmodule.exports = open;\nmodule.exports.factory = function(cmd, settings) {\n  return function openInEditor(filename) {\n    return open(cmd, filename, settings);\n  };\n};\n\nmodule.exports.detectAndOpenFactory = function(detect, settings) {\n  return function openInEditor(filename) {\n    return detect().then(function(cmd) {\n      open(cmd, filename, settings);\n    });\n  };\n};\n"
  },
  {
    "path": "lib/utils.js",
    "content": "var osHomeDir = require('os-homedir')();\nvar path = require('path');\n\nmodule.exports = {\n  number: function(value, fallback) {\n    return isNaN(value) ? fallback : value;\n  },\n  quote: function(value, escapeQuotes) {\n    value = String(value)\n      .replace(/\\\\/g, '\\\\\\\\')\n      .replace(/\"/g, '\\\"');\n\n    return escapeQuotes ?\n      '\\\\\"' + value + '\\\\\"' :\n      '\"' + value + '\"';\n  },\n  extractFilename: function(filename) {\n    var parts = filename.match(/^(.+?)((?::\\d+){0,4})$/);\n    var segment = parts[2].split(':').slice(1);\n\n    return {\n      filename: parts[1],\n      line: parseInt(segment[0] || 0, 10),\n      column: parseInt(segment[1] || 0, 10)\n    };\n  },\n  fail: function(msg) {\n    console.error(String(msg).trimRight());\n    process.exit(2);\n  },\n  atHomeDir: function(filename) {\n    return path.join(osHomeDir, filename);\n  },\n  any: function(promises, err) {\n    return new Promise(function(resolve, reject) {\n      Promise.all(promises.map(function(item) {\n        if (item && typeof item.then == 'function') {\n          return item.then(\n            resolve,    // any success resolves the main promise immediately\n            function() { /* ignore any reject */ }\n          );\n        }\n\n        return item;\n      })).then(function(results) {\n        reject(err);\n      }, reject);\n    });\n  },\n  append: function(str, appendix) {\n    return String(str).replace(/\\s*$/, (str ? ' ' : '') + appendix);\n  },\n  assign: function(dest, src) {\n    for (var key in src) {\n      if (Object.prototype.hasOwnProperty.call(src, key)) {\n        dest[key] = src[key];\n      }\n    }\n\n    return dest;\n  }\n};\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"open-in-editor\",\n  \"description\": \"Open file in editor\",\n  \"version\": \"2.2.0\",\n  \"author\": \"Roman Dvornov <rdvornov@gmail.com>\",\n  \"license\": \"MIT\",\n  \"repository\": \"lahmatiy/open-in-editor\",\n  \"keywords\": [\n    \"open\",\n    \"file\",\n    \"editor\",\n    \"atom\",\n    \"code\",\n    \"vscode\",\n    \"idea\",\n    \"phpstorm\",\n    \"webstorm\",\n    \"sublime\",\n    \"visual studio\",\n    \"vim\",\n    \"emacs\"\n  ],\n  \"main\": \"./lib/index.js\",\n  \"engines\": {\n    \"node\": \">=0.12.0\"\n  },\n  \"bin\": {\n    \"oe\": \"./bin/oe\"\n  },\n  \"dependencies\": {\n    \"clap\": \"^1.1.3\",\n    \"os-homedir\": \"~1.0.2\"\n  },\n  \"devDependencies\": {},\n  \"scripts\": {}\n}\n"
  }
]