Created
January 23, 2018 09:47
-
-
Save neroze/3189adb84733fd6bc04296f57d6126eb to your computer and use it in GitHub Desktop.
CLI App chooser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inquirer = require('inquirer'); | |
const util = require('util'); | |
const exec = util.promisify(require('child_process').exec); | |
// var process = require('process'); | |
async function goToApp(app = '~') { | |
const _cd = `cd ${app.path}` | |
console.log(`guake -n guake -e cd ${_cd} && fish && ${app.cmd}`); | |
// const { stdout, stderr } = await exec(`guake -n guake -e ${_cd}`); | |
// const { stdout, stderr } = await exec(`guake -n guake -e 'cd /home/dragonlaw/jumper/DLapp && fish'`); | |
const { stdout, stderr } = await exec(`guake -n guake -e '${_cd} && fish'`); | |
// app.cmd && openmoreApp(app.cmd) | |
} | |
async function openmoreApp(cmd) { | |
const { stdout2, stderr2 } = await exec(`${app.cmd}`); | |
} | |
function selectAppPath(app) { | |
let action; | |
switch (app) { | |
case 'webapp': | |
action = { | |
path: '~/dragonApps/dragonlawWebApp/', | |
cmd: 'webapp' | |
}; | |
break; | |
case 'adminapp': | |
action = { | |
path: '~/dragonApps/adminApp/', | |
cmd: 'adminapp' | |
}; | |
break; | |
case 'regapp': | |
action = { | |
path: '~/dragonApps/regApp/', | |
cmd: '' | |
}; | |
break; | |
default : | |
action = { | |
path: '~/dragonApps/dragonlawWebApp/', | |
cmd: 'webapp' | |
}; | |
// case 'dte': | |
// path = '~/dragonApps/dragonlawWebApp/'; | |
// break; | |
} | |
return action | |
} | |
inquirer.prompt([ | |
{ | |
type: 'list', | |
name: 'app', | |
message: 'What size do you need?', | |
choices: ['WebApp', 'AdminApp', 'RegApp', 'DTE'], | |
filter: function(val) { | |
return val.toLowerCase(); | |
} | |
} | |
]).then(answer => { | |
console.log('answers', answer); | |
goToApp(selectAppPath(answer.app)) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment