diff options
author | lassulus <lassulus@lassul.us> | 2021-02-11 11:09:03 +0100 |
---|---|---|
committer | lassulus <lassulus@lassul.us> | 2021-02-11 11:09:03 +0100 |
commit | 3054b326ef5e9d92ef8d26b50db5546691c24d59 (patch) | |
tree | 26eeae9a61206a5fddba5690729e2ee2f7ab52e6 /tv/5pkgs/simple/xdpytools/src/xdpysel | |
parent | f0e8399b81b911da6c88d7af442bc305a1827c66 (diff) | |
parent | bda725bbfc4a4e1ecf8a8fd8d3dbff69b5cf4d60 (diff) |
Merge remote-tracking branch 'ni/master'
Diffstat (limited to 'tv/5pkgs/simple/xdpytools/src/xdpysel')
-rwxr-xr-x | tv/5pkgs/simple/xdpytools/src/xdpysel | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tv/5pkgs/simple/xdpytools/src/xdpysel b/tv/5pkgs/simple/xdpytools/src/xdpysel new file mode 100755 index 000000000..e08015576 --- /dev/null +++ b/tv/5pkgs/simple/xdpytools/src/xdpysel @@ -0,0 +1,49 @@ +#! /bin/sh +# usage: xdpysel {prev,next} +# Print the number of the selected X display. + +find /tmp/.X11-unix -mindepth 1 -maxdepth 1 | +jq -Rrs --arg command "$1" ' + ( + split("\n") | + map( + select(.!="") | + match("^.*/X([0-9]+)$").captures[0].string | + tonumber + ) + ) + as $all_displays | + + ( + env.DISPLAY | + match("^:([0-9]+)(?:[.][0-9]+)?$").captures[0].string | + tonumber + ) + as $current_display | + + ($all_displays | length) as $all_displays_count | + + ($all_displays|index($current_display)) + as $current_index | + + (($current_index + 1) % $all_displays_count) + as $next_index | + + (($all_displays_count + $current_index - 1) % $all_displays_count) + as $prev_index | + + $all_displays[$prev_index] as $prev_display | + $all_displays[$next_index] as $next_display | + + { + prev: $prev_display, + next: $next_display, + }[$command] + as $result | + + if $result | type == "number" then + $result + else + "xdpysel: bad argument: \($command)\n" | halt_error(-1) + end +' |