Skip to content

Instantly share code, notes, and snippets.

@guzart
Last active October 12, 2016 16:08
Show Gist options
  • Save guzart/5762776 to your computer and use it in GitHub Desktop.
Save guzart/5762776 to your computer and use it in GitHub Desktop.
Load and unload homebrew plist files
#!/usr/bin/env node
var spawn = require('child_process').spawn;
var action = 'Load';
if (process.argv[2] === '-u') {
action = 'Unload';
}
for (var i = 0, f = process.argv.length; i < f; i += 1) {
var name = process.argv[i];
var plist = getPlist(name);
if (plist) {
console.log(action + 'ing ' + name + '...');
spawn('launchctl', [action.toLowerCase(), plist], {stdio: [0, 'pipe']});
}
}
function getPlist(name) {
switch(name) {
case 'redis':
return '/usr/local/opt/redis/homebrew.mxcl.redis.plist';
case 'couchdb':
return '/usr/local/opt/couchdb/homebrew.mxcl.couchdb.plist';
case 'postgres':
case 'postgresql':
return '/usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist';
default:
return null;
}
}
#!/usr/bin/env node
const execSync = require('child_process').execSync;
const parseArgv = require('minimist');
const argv = parseArgv(process.argv);
const library = argv.u || argv._[argv._.length - 1];
const action = argv.u ? 'unload' : 'load';
function getLaunchFilepath(lib) {
switch (lib) {
case 'postgres':
return '/usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist';
case 'redis':
return '/usr/local/opt/redis/homebrew.mxcl.redis.plist';
}
}
const ctl = getLaunchFilepath(library);
const command = `launchctl ${action} ${ctl}`;
console.log(command);
execSync(command);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment