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');
|
console.log('Detected devices:\n');
|
||||||
Object.keys(devices)
|
Object.keys(devices)
|
||||||
.sort(key => !devices[key].connected)
|
.sort(key => !devices[key].connected)
|
||||||
.forEach(key => console.log(key + ':', connectionStatus(devices[key])));
|
.forEach(key =>
|
||||||
|
console.log(key + ':', connectionStatus(devices[key]))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let selectedMonitors = argv._;
|
let selectedMonitors = argv._;
|
||||||
@@ -39,13 +41,19 @@ if (argv.help || argv.h) {
|
|||||||
console.log('Using profile', profile);
|
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) => {
|
swm.getDevices((err, devices) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
}
|
}
|
||||||
const xrandrOptions = swm.generateXrandrOptions(selectedMonitors, devices);
|
const xrandrOptions = swm.generateXrandrOptions(
|
||||||
|
selectedMonitors,
|
||||||
|
devices
|
||||||
|
);
|
||||||
swm.switchDevices(xrandrOptions);
|
swm.switchDevices(xrandrOptions);
|
||||||
swm.executePostCmd(postCmd);
|
swm.executePostCmd(postCmd);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ const configPath = require('xdg').basedir.configPath('switchmon/config.json');
|
|||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
postCmd: undefined,
|
postCmd: undefined,
|
||||||
profiles: {},
|
profiles: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let config = Object.assign({}, defaults);
|
let config = Object.assign({}, defaults);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = Object.assign(config, require(configPath));
|
config = Object.assign(config, require(configPath));
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
if (err.code !== 'MODULE_NOT_FOUND') {
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|||||||
77
package.json
77
package.json
@@ -1,40 +1,41 @@
|
|||||||
{
|
{
|
||||||
"name": "switchmon",
|
"name": "switchmon",
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"description": "Simple helper for turning on/off connected/disconnected monitors with xrandr",
|
"description": "Simple helper for turning on/off connected/disconnected monitors with xrandr",
|
||||||
"main": "cli.js",
|
"main": "cli.js",
|
||||||
"scripts": {
|
"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",
|
"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"
|
"testwatch": "mocha -w"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"swm": "./cli.js"
|
"swm": "./cli.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/tomru/switchmon.git"
|
"url": "git+https://github.com/tomru/switchmon.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": ["xrandr", "monitor"],
|
||||||
"xrandr",
|
"author": "Thomas Ruoff",
|
||||||
"monitor"
|
"license": "MIT",
|
||||||
],
|
"bugs": {
|
||||||
"author": "Thomas Ruoff",
|
"url": "https://github.com/tomru/switchmon/issues"
|
||||||
"license": "MIT",
|
},
|
||||||
"bugs": {
|
"homepage": "https://github.com/tomru/switchmon#readme",
|
||||||
"url": "https://github.com/tomru/switchmon/issues"
|
"dependencies": {
|
||||||
},
|
"minimist": "^1.2.0",
|
||||||
"homepage": "https://github.com/tomru/switchmon#readme",
|
"xdg": "^0.1.1",
|
||||||
"dependencies": {
|
"xrandr-parse": "^0.1.1"
|
||||||
"minimist": "^1.2.0",
|
},
|
||||||
"xdg": "^0.1.1",
|
"devDependencies": {
|
||||||
"xrandr-parse": "^0.1.1"
|
"coveralls": "^2.11.8",
|
||||||
},
|
"istanbul": "^0.4.2",
|
||||||
"devDependencies": {
|
"mocha": "^2.4.5",
|
||||||
"coveralls": "^2.11.8",
|
"mocha-lcov-reporter": "^1.2.0",
|
||||||
"istanbul": "^0.4.2",
|
"proxyquire": "^1.7.4",
|
||||||
"mocha": "^2.4.5",
|
"sinon": "^1.17.3"
|
||||||
"mocha-lcov-reporter": "^1.2.0",
|
},
|
||||||
"proxyquire": "^1.7.4",
|
"prettier": {
|
||||||
"sinon": "^1.17.3"
|
"tabWidth": 4,
|
||||||
}
|
"singleQuote": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
swm.js
6
swm.js
@@ -8,7 +8,9 @@ function executeCmd(cmd, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDevices(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) {
|
function switchDevices(xrandrOptions, callback) {
|
||||||
@@ -23,7 +25,7 @@ function orderDeviceKeys(selectedDevices, devices) {
|
|||||||
let orderedDeviceKeys = Object.keys(devices).sort();
|
let orderedDeviceKeys = Object.keys(devices).sort();
|
||||||
|
|
||||||
// fix the sort order if monitors were explicitly selected
|
// fix the sort order if monitors were explicitly selected
|
||||||
selectedDevices.reverse().forEach((monitor) => {
|
selectedDevices.reverse().forEach(monitor => {
|
||||||
const index = orderedDeviceKeys.indexOf(monitor);
|
const index = orderedDeviceKeys.indexOf(monitor);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
console.error('Unkown monitor', monitor, '(ignored)');
|
console.error('Unkown monitor', monitor, '(ignored)');
|
||||||
|
|||||||
Reference in New Issue
Block a user