~mil/sxmo-utils

ref: 35b312c0b8852ce7addd086ac53713fabb3a6c2d sxmo-utils/scripts/core/sxmo_sws.sh -rwxr-xr-x 1.4 KiB
35b312c0 — ~baroque0 added scripts/core/sxmo_sws.sh sway window switcher a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
#
# Initial author: Adrien Le Guillou
# License: MIT
#
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

set -e # error if a command as non 0 exit
set -u # error if undefined variable


# Default parameters
FORMAT="W:%W | %A - %T"
DMENU="sxmo_dmenu.sh"

# FORMAT as a `jq` concatenation string
FORMAT="$FORMAT (%I)"
FORMAT=$(echo "$FORMAT" | \
        sed  's/%O/" + .output + "/
              s/%W/" + .workspace + "/
              s/%A/" + .app_id + "/
              s/%T/" + .name + "/
              s/%I/" + .id + "/
              s/"/\"/
              s/\(.*\)/\"\1\"/')

# Get the container ID from the node tree
CON_ID=$(swaymsg -t get_tree | \
    jq -r ".nodes[]
        | {output: .name, content: .nodes[]}
        | {output: .output, workspace: .content.name,
          apps: .content
            | ..
            | {id: .id?|tostring, name: .name?, app_id: .app_id?, shell: .shell?}
            | select(.app_id != null or .shell != null)}
        | {output: .output, workspace: .workspace,
           id: .apps.id, app_id: .apps.app_id, name: .apps.name }
        | $FORMAT
        | tostring" | \
    $DMENU -i -p "Window Switcher")

# Requires the actual `id` to be at the end and between paretheses
CON_ID=${CON_ID##*(}
CON_ID=${CON_ID%)}

# Focus on the chosen window
swaymsg "[con_id=$CON_ID]" focus