From 5699c8d928760b9abf2dea13ec4993096455cf1e Mon Sep 17 00:00:00 2001 From: Stephen Pennell Date: Tue, 7 Nov 2017 12:19:57 -0500 Subject: [PATCH] Handles spaces in `$PATH` Issue #86 --- lib/alfred-exec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/alfred-exec.js b/lib/alfred-exec.js index 160b122..3729fac 100644 --- a/lib/alfred-exec.js +++ b/lib/alfred-exec.js @@ -2,16 +2,16 @@ const child = require('child_process'); let shell = process.env.SHELL; let escChr = str => str.replace(/(["\$])/g, '\\$1'); let escSpace = str => str.replace(/ /g, '\\ '); -const PATH = `eval $(/usr/libexec/path_helper | awk '{print $1}')`; +const PATH = `eval $(echo "$(/usr/libexec/path_helper -s)" | awk -F';' '{ print $1 }');`; module.exports = { 'exec': (cmd, options, callback) => { - cmd = escChr(cmd); - return child.exec(`${shell} -c "${PATH} ${cmd}"`, options, callback); + cmd = escChr(`${PATH} ${cmd}`); + return child.exec(`${shell} -c "${cmd}"`, options, callback); }, 'execSync': (cmd, options) => { - cmd = escChr(cmd); - return child.execSync(`${shell} -c "${PATH} ${cmd}"`, options); + cmd = escChr(`${PATH} ${cmd}`); + return child.execSync(`${shell} -c "${cmd}"`, options); }, 'spawn': (cmd, args, options) => { args = args.map(escSpace)