From a0150db13632a20631af8f30c0d89cb785de8f08 Mon Sep 17 00:00:00 2001 From: Roman Kuraev Date: Mon, 21 Aug 2017 13:17:59 +0300 Subject: [PATCH 1/2] Add support for executing external command on detected fileName string --- lib/main.coffee | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/main.coffee b/lib/main.coffee index 85fd39d..f4b1ea3 100644 --- a/lib/main.coffee +++ b/lib/main.coffee @@ -1,6 +1,7 @@ path = require 'path' fs = require 'fs-plus' _ = require 'underscore-plus' +execSync = require("child_process").execSync getBaseName = (file) -> path.basename(file, path.extname(file)) @@ -13,6 +14,13 @@ commandsDisposer = null FileNameRegexp = /[-\w/\.]+(:\d+){0,2}/g module.exports = + config: + customSearchCommand: + title: 'Custom search command' + description: 'Shell command to find files. Executed with environment variable `$FILENAME`. Example: `grealpath $(find . -name $FILENAME)`' + type: 'string', + default: '' + activate: (state) -> commandsDisposer = atom.commands.add 'atom-text-editor', 'open-this:here': => @open() @@ -80,7 +88,24 @@ module.exports = # Search from projectRoot for dir in atom.project.getPaths() when dirName.startsWith(dir) - return @detectFilePath(path.resolve(dir, fileName)) + if filePath = @detectFilePath(path.resolve(dir, fileName)) + return filePath + + # Execute external command defined in config + if atom.config.get(PACKAGE_NAME + '.customSearchCommand') + for dir in atom.project.getPaths() + try + if filePath = execSync ['FILENAME=' + fileName, + atom.config.get('open-this.customSearchCommand')].join(';'), { + cwd: dir + encoding: 'utf8' + } + return filePath + catch err + console.log 'Custom search command returned non-zero exit code.', + stdout: err.stdout, + stderr: err.stderr + null open: (split) -> From 68dffea4f5a20ee59c1c8485d720a935008d8fc4 Mon Sep 17 00:00:00 2001 From: Roman Kuraev Date: Mon, 21 Aug 2017 13:41:40 +0300 Subject: [PATCH 2/2] bugfix --- lib/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.coffee b/lib/main.coffee index f4b1ea3..8e330dc 100644 --- a/lib/main.coffee +++ b/lib/main.coffee @@ -92,7 +92,7 @@ module.exports = return filePath # Execute external command defined in config - if atom.config.get(PACKAGE_NAME + '.customSearchCommand') + if atom.config.get('open-this.customSearchCommand') for dir in atom.project.getPaths() try if filePath = execSync ['FILENAME=' + fileName,