mirror of
https://github.com/tomru/switchmon.git
synced 2026-03-03 06:27:23 +01:00
add prettier
This commit is contained in:
14
cli.js
14
cli.js
@@ -25,7 +25,9 @@ if (argv.help || argv.h) {
|
||||
console.log('Detected devices:\n');
|
||||
Object.keys(devices)
|
||||
.sort(key => !devices[key].connected)
|
||||
.forEach(key => console.log(key + ':', connectionStatus(devices[key])));
|
||||
.forEach(key =>
|
||||
console.log(key + ':', connectionStatus(devices[key]))
|
||||
);
|
||||
});
|
||||
} else {
|
||||
let selectedMonitors = argv._;
|
||||
@@ -39,13 +41,19 @@ if (argv.help || argv.h) {
|
||||
console.log('Using profile', profile);
|
||||
}
|
||||
|
||||
console.log('Switching on', selectedMonitors.length ? selectedMonitors : 'all connected monitors');
|
||||
console.log(
|
||||
'Switching on',
|
||||
selectedMonitors.length ? selectedMonitors : 'all connected monitors'
|
||||
);
|
||||
|
||||
swm.getDevices((err, devices) => {
|
||||
if (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
const xrandrOptions = swm.generateXrandrOptions(selectedMonitors, devices);
|
||||
const xrandrOptions = swm.generateXrandrOptions(
|
||||
selectedMonitors,
|
||||
devices
|
||||
);
|
||||
swm.switchDevices(xrandrOptions);
|
||||
swm.executePostCmd(postCmd);
|
||||
});
|
||||
|
||||
@@ -4,14 +4,14 @@ const configPath = require('xdg').basedir.configPath('switchmon/config.json');
|
||||
|
||||
const defaults = {
|
||||
postCmd: undefined,
|
||||
profiles: {},
|
||||
profiles: {}
|
||||
};
|
||||
|
||||
let config = Object.assign({}, defaults);
|
||||
|
||||
try {
|
||||
config = Object.assign(config, require(configPath));
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
if (err.code !== 'MODULE_NOT_FOUND') {
|
||||
throw err;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,7 @@
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tomru/switchmon.git"
|
||||
},
|
||||
"keywords": [
|
||||
"xrandr",
|
||||
"monitor"
|
||||
],
|
||||
"keywords": ["xrandr", "monitor"],
|
||||
"author": "Thomas Ruoff",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
@@ -36,5 +33,9 @@
|
||||
"mocha-lcov-reporter": "^1.2.0",
|
||||
"proxyquire": "^1.7.4",
|
||||
"sinon": "^1.17.3"
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 4,
|
||||
"singleQuote": true
|
||||
}
|
||||
}
|
||||
|
||||
6
swm.js
6
swm.js
@@ -8,7 +8,9 @@ function executeCmd(cmd, callback) {
|
||||
}
|
||||
|
||||
function getDevices(callback) {
|
||||
executeCmd('xrandr', (err, stdout) => callback(err, err ? null : xrandrParse(stdout)));
|
||||
executeCmd('xrandr', (err, stdout) =>
|
||||
callback(err, err ? null : xrandrParse(stdout))
|
||||
);
|
||||
}
|
||||
|
||||
function switchDevices(xrandrOptions, callback) {
|
||||
@@ -23,7 +25,7 @@ function orderDeviceKeys(selectedDevices, devices) {
|
||||
let orderedDeviceKeys = Object.keys(devices).sort();
|
||||
|
||||
// fix the sort order if monitors were explicitly selected
|
||||
selectedDevices.reverse().forEach((monitor) => {
|
||||
selectedDevices.reverse().forEach(monitor => {
|
||||
const index = orderedDeviceKeys.indexOf(monitor);
|
||||
if (index < 0) {
|
||||
console.error('Unkown monitor', monitor, '(ignored)');
|
||||
|
||||
Reference in New Issue
Block a user