Skip to content

Commit

Permalink
Handles spaces in $PATH
Browse files Browse the repository at this point in the history
Issue #86
  • Loading branch information
steyep committed Nov 7, 2017
1 parent 556de68 commit 5699c8d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/alfred-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5699c8d

Please sign in to comment.