add support for predefined profiles

This commit is contained in:
Thomas Ruoff
2016-03-01 23:38:24 +01:00
parent 3b0ee78cf4
commit e3054967b4
3 changed files with 31 additions and 4 deletions

22
cli.js
View File

@@ -5,6 +5,7 @@ const argv = require('minimist')(process.argv.slice(2));
const swm = require('./swm.js');
const config = require('./config.js');
const postCmd = argv.postCmd || config.postCmd;
const profile = argv.profile || argv.p;
if (argv.help || argv.h) {
console.log(
@@ -41,8 +42,10 @@ the form of
process.exit(2);
}
const devices = swm.getDevices();
if (argv.list || argv.l) {
swm.getDevices()
devices
.then(devices => {
console.log('Detected devices:\n');
Object.keys(devices)
@@ -51,8 +54,21 @@ if (argv.list || argv.l) {
process.exit(0);
});
} else {
swm.getDevices()
.then(swm.generateXrandrOptions.bind(null, argv._))
let selectedMonitors = argv._;
if (profile) {
if (!config.profiles[profile]) {
console.error('profile', profile, 'not found in config');
process.exit(1);
}
selectedMonitors = config.profiles[profile];
console.log('Using profile', profile);
}
console.log('Switching on', selectedMonitors);
devices
.then(swm.generateXrandrOptions.bind(null, selectedMonitors))
.then(swm.switchDevices)
.then(swm.executePostCmd.bind(null, postCmd))
.catch(err => {