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;
|
||||
}
|
||||
|
||||
77
package.json
77
package.json
@@ -1,40 +1,41 @@
|
||||
{
|
||||
"name": "switchmon",
|
||||
"version": "1.2.0",
|
||||
"description": "Simple helper for turning on/off connected/disconnected monitors with xrandr",
|
||||
"main": "cli.js",
|
||||
"scripts": {
|
||||
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
|
||||
"testwatch": "mocha -w"
|
||||
},
|
||||
"bin": {
|
||||
"swm": "./cli.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tomru/switchmon.git"
|
||||
},
|
||||
"keywords": [
|
||||
"xrandr",
|
||||
"monitor"
|
||||
],
|
||||
"author": "Thomas Ruoff",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/tomru/switchmon/issues"
|
||||
},
|
||||
"homepage": "https://github.com/tomru/switchmon#readme",
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.0",
|
||||
"xdg": "^0.1.1",
|
||||
"xrandr-parse": "^0.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.8",
|
||||
"istanbul": "^0.4.2",
|
||||
"mocha": "^2.4.5",
|
||||
"mocha-lcov-reporter": "^1.2.0",
|
||||
"proxyquire": "^1.7.4",
|
||||
"sinon": "^1.17.3"
|
||||
}
|
||||
"name": "switchmon",
|
||||
"version": "1.2.0",
|
||||
"description": "Simple helper for turning on/off connected/disconnected monitors with xrandr",
|
||||
"main": "cli.js",
|
||||
"scripts": {
|
||||
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
|
||||
"testwatch": "mocha -w"
|
||||
},
|
||||
"bin": {
|
||||
"swm": "./cli.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tomru/switchmon.git"
|
||||
},
|
||||
"keywords": ["xrandr", "monitor"],
|
||||
"author": "Thomas Ruoff",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/tomru/switchmon/issues"
|
||||
},
|
||||
"homepage": "https://github.com/tomru/switchmon#readme",
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.0",
|
||||
"xdg": "^0.1.1",
|
||||
"xrandr-parse": "^0.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.8",
|
||||
"istanbul": "^0.4.2",
|
||||
"mocha": "^2.4.5",
|
||||
"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