mirror of
https://github.com/tomru/switchmon.git
synced 2026-03-03 06:27:23 +01:00
update readme and usage
This commit is contained in:
41
README.md
41
README.md
@@ -2,30 +2,51 @@
|
|||||||
|
|
||||||
Simple helper for turning on/off connected/disconnected monitors with `xrandr`.
|
Simple helper for turning on/off connected/disconnected monitors with `xrandr`.
|
||||||
|
|
||||||
## Usage
|
## Synopsis
|
||||||
`swm [monitor-1...montior-n] [--postCmd="cmd"]` e.g. `swm LVDS1 HDMI1`
|
`swm`
|
||||||
|
|
||||||
If `monitor-1` to `monitor-n` is specified `swm` will turn on these monitors
|
`swm [monitor-1..montior-n]`
|
||||||
and place them from left to right in the order given. If a provided monitor is
|
|
||||||
not connected it will be skipped.
|
`swm --profile external`
|
||||||
|
|
||||||
|
`swm --list`
|
||||||
|
|
||||||
|
## Description
|
||||||
|
To turn on/off connected/disconnected monitors.
|
||||||
|
|
||||||
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.
|
If monitors `monitor-1..monitor-n` are specified these monitors will be turned
|
||||||
This is usefull to tell your window manager to re-detect monitors, e.g. for
|
on and place them from left to right in the order given.
|
||||||
herbstluftwm `herbstclient reload`.
|
|
||||||
|
|
||||||
`swm -l` or `swm --list`
|
* `--profile profilename` or `-p profilename`
|
||||||
|
|
||||||
|
If a profile is specified, the configured monitors will be turned on.
|
||||||
|
|
||||||
|
* `--postCmd "some cmd"`
|
||||||
|
|
||||||
|
A post 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`.
|
||||||
|
|
||||||
|
* `-l` or `swm --list`
|
||||||
|
|
||||||
List all devices with the connectivity status.
|
List all devices with the connectivity status.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
The configuration can be placed in `$XDG_CONFIG_HOME/switchmon/config.json` in
|
The configuration can be placed in `$XDG_CONFIG_HOME/switchmon/config.json` in
|
||||||
the form of
|
the form of
|
||||||
|
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
"postCmd": "some command"
|
"postCmd": "some command",
|
||||||
|
"profiles": {
|
||||||
|
"internal": ["LVDS1"],
|
||||||
|
"external": ["HDMI1"],
|
||||||
|
"dual": ["LVDS1", "HDMI1"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
44
cli.js
44
cli.js
@@ -2,44 +2,21 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
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 config = require('./config.js');
|
||||||
|
const usage = require('./usage.js');
|
||||||
|
|
||||||
const postCmd = argv.postCmd || config.postCmd;
|
const postCmd = argv.postCmd || config.postCmd;
|
||||||
const profile = argv.profile || argv.p;
|
const profile = argv.profile || argv.p;
|
||||||
|
|
||||||
|
function connectionStatus(device) {
|
||||||
|
return device.connected ? 'Connected' : 'Disconnected';
|
||||||
|
}
|
||||||
|
|
||||||
if (argv.help || argv.h) {
|
if (argv.help || argv.h) {
|
||||||
console.log(
|
console.log(usage);
|
||||||
`Simple helper for turning on/off connected/disconnected monitors with 'xrandr'.
|
process.exit(0);
|
||||||
|
|
||||||
Usage:
|
|
||||||
|
|
||||||
'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
|
|
||||||
and place them from left to right in the order given. If a provided monitor is
|
|
||||||
not connected it will be skipped.
|
|
||||||
|
|
||||||
If no monitors are specified all connected monitors will be turned on and
|
|
||||||
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"
|
|
||||||
}`
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const devices = swm.getDevices();
|
const devices = swm.getDevices();
|
||||||
@@ -50,7 +27,7 @@ if (argv.list || argv.l) {
|
|||||||
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 + ':', devices[key].connected ? 'Connected' : 'Disconnected'));
|
.forEach(key => console.log(key + ':', connectionStatus(devices[key])));
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -73,5 +50,6 @@ if (argv.list || argv.l) {
|
|||||||
.then(swm.executePostCmd.bind(null, postCmd))
|
.then(swm.executePostCmd.bind(null, postCmd))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
process.exit(2);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
47
usage.js
Normal file
47
usage.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
const usage = `Synopsis
|
||||||
|
|
||||||
|
swm
|
||||||
|
swm [monitor-1..montior-n]
|
||||||
|
swm --profile external
|
||||||
|
swm --list
|
||||||
|
|
||||||
|
Description
|
||||||
|
|
||||||
|
To turn on/off connected/disconnected monitors.
|
||||||
|
|
||||||
|
If no monitors are specified all connected monitors will be turned on and
|
||||||
|
placed from left to right in alphabetical order of their name.
|
||||||
|
|
||||||
|
If monitors monitor-1..monitor-n are specified these monitors will be turned
|
||||||
|
on and place them from left to right in the order given.
|
||||||
|
|
||||||
|
--profile profilename or -p profilename
|
||||||
|
If a profile is specified, the configured monitors will be turned on.
|
||||||
|
|
||||||
|
--postCmd "some cmd"
|
||||||
|
|
||||||
|
A post 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.
|
||||||
|
|
||||||
|
-l or swm --list
|
||||||
|
|
||||||
|
List all devices with the connectivity status.
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
|
||||||
|
The configuration can be placed in $XDG_CONFIG_HOME/switchmon/config.json in
|
||||||
|
the form of
|
||||||
|
|
||||||
|
{
|
||||||
|
"postCmd": "some command",
|
||||||
|
"profiles": {
|
||||||
|
"internal": ["LVDS1"],
|
||||||
|
"external": ["HDMI1"],
|
||||||
|
"dual": ["LVDS1", "HDMI1"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
|
module.exports = usage;
|
||||||
Reference in New Issue
Block a user