mirror of
https://github.com/tomru/switchmon.git
synced 2026-03-03 06:27:23 +01:00
add optional config for postCmd
This commit is contained in:
20
README.md
20
README.md
@@ -3,8 +3,7 @@
|
|||||||
Simple helper for turning on/off connected/disconnected monitors with `xrandr`.
|
Simple helper for turning on/off connected/disconnected monitors with `xrandr`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
`swm [monitor-1...montior-n] [--postCmd="cmd"]` e.g. `swm LVDS1 HDMI1`
|
||||||
`swm [monitor-1...montior-n]` e.g. `swm LVDS1 HDMI1`
|
|
||||||
|
|
||||||
If `monitor-1` to `monitor-n` is specified `swm` will turn on these monitors
|
If `monitor-1` to `monitor-n` is specified `swm` will turn on these monitors
|
||||||
and place them from left to right in the order given. If a provided monitor is
|
and place them from left to right in the order given. If a provided monitor is
|
||||||
@@ -13,6 +12,23 @@ not connected it will be skipped.
|
|||||||
If no monitors are specified all connected monitors will be turned on and
|
If no monitors are specified all connected monitors will be turned on and
|
||||||
placed from left to right in alphabetical order of their name.
|
placed from left to right in alphabetical order of their name.
|
||||||
|
|
||||||
|
If `--postCmd` is given, this command is executed after switching the monitors.
|
||||||
|
This is usefull to tell your window manager to re-detect monitors, e.g. for
|
||||||
|
herbstluftwm `herbstclient reload`.
|
||||||
|
|
||||||
|
`swm -l` or `swm --list`
|
||||||
|
|
||||||
|
List all devices with the connectivity status.
|
||||||
|
|
||||||
|
The configuration can be placed in `$XDG_CONFIG_HOME/switchmon/config.json` in
|
||||||
|
the form of
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"postCmd": "some command"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
Node.js > 4.x on your PATH.
|
Node.js > 4.x on your PATH.
|
||||||
|
|||||||
20
cli.js
20
cli.js
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
const argv = require('minimist')(process.argv.slice(2));
|
const argv = require('minimist')(process.argv.slice(2));
|
||||||
const swm = require('./swm.js');
|
const swm = require('./swm.js');
|
||||||
|
const config = require('./config.js');
|
||||||
|
const postCmd = argv.postCmd || config.postCmd;
|
||||||
|
|
||||||
if (argv.help || argv.h) {
|
if (argv.help || argv.h) {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -10,7 +12,7 @@ if (argv.help || argv.h) {
|
|||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
'swm [monitor-1...montior-n]' e.g. 'swm LVDS1 HDMI1'
|
'swm [monitor-1...montior-n] [--postCmd="cmd"]' e.g. 'swm LVDS1 HDMI1'
|
||||||
|
|
||||||
If 'monitor-1' to 'monitor-n' is specified 'swm' will turn on these monitors
|
If 'monitor-1' to 'monitor-n' is specified 'swm' will turn on these monitors
|
||||||
and place them from left to right in the order given. If a provided monitor is
|
and place them from left to right in the order given. If a provided monitor is
|
||||||
@@ -19,9 +21,21 @@ not connected it will be skipped.
|
|||||||
If no monitors are specified all connected monitors will be turned on and
|
If no monitors are specified all connected monitors will be turned on and
|
||||||
placed from left to right in alphabetical order of their name.
|
placed from left to right in alphabetical order of their name.
|
||||||
|
|
||||||
|
If "--postCmd" is given, this command is executed after switching the monitors.
|
||||||
|
This is usefull to tell your window manager to re-detect monitors, e.g. for
|
||||||
|
herbstluftwm "herbstclient reload".
|
||||||
|
|
||||||
'swm -l' or 'swm --list'
|
'swm -l' or 'swm --list'
|
||||||
|
|
||||||
List all devices with the connectivity status.`
|
List all devices with the connectivity status.
|
||||||
|
|
||||||
|
The configuration can be placed in "$XDG_CONFIG_HOME/switchmon/config.json" in
|
||||||
|
the form of
|
||||||
|
|
||||||
|
{
|
||||||
|
"postCmd": "some command"
|
||||||
|
}`
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
@@ -40,7 +54,7 @@ if (argv.list || argv.l) {
|
|||||||
swm.getDevices()
|
swm.getDevices()
|
||||||
.then(swm.generateXrandrOptions.bind(null, argv._))
|
.then(swm.generateXrandrOptions.bind(null, argv._))
|
||||||
.then(swm.switchDevices)
|
.then(swm.switchDevices)
|
||||||
.then(swm.executePostCmd.bind(null, argv.postCmd))
|
.then(swm.executePostCmd.bind(null, postCmd))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
|
|||||||
17
config.js
Normal file
17
config.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const configPath = require('xdg').basedir.configPath('switchmon/config.json');
|
||||||
|
|
||||||
|
const defaults = {
|
||||||
|
postCmd: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
let config = Object.assign({}, defaults);
|
||||||
|
|
||||||
|
try {
|
||||||
|
config = Object.assign(config, require(configPath));
|
||||||
|
} catch(err) {
|
||||||
|
// No config found in "${configPath}". Using defaults...
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = config;
|
||||||
@@ -6,7 +6,9 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"bin" : { "swm" : "./cli.js" },
|
"bin": {
|
||||||
|
"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"
|
||||||
@@ -23,6 +25,7 @@
|
|||||||
"homepage": "https://github.com/tomru/switchmon#readme",
|
"homepage": "https://github.com/tomru/switchmon#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
|
"xdg": "^0.1.1",
|
||||||
"xrandr-parse": "^0.1.1"
|
"xrandr-parse": "^0.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user