aboutsummaryrefslogtreecommitdiff
path: root/sway/terminal.sh
blob: 3929f82caa42d4dd4dd873533c1ce730b96e615b (plain) (blame)
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
#!/bin/sh

term_workspace="9:term"
term_app_id=tmux_term

focused_output=$(swaymsg -t get_outputs -r |
                 jq -r '.[] | select(.focused == true) | .name')
focused_workspace=$(swaymsg -t get_workspaces -r |
                    jq -r '.[] | select(.focused == true) | .name')

if [ "$focused_workspace" = "$term_workspace" ]; then
    swaymsg -q workspace back_and_forth

else
    swaymsg -q workspace $term_workspace
    swaymsg -q move workspace to $focused_output
    swaymsg -q workspace $term_workspace

    if ! (swaymsg -t get_tree -r |
          jq -e "recurse(.nodes[]) | select(.app_id == \"$term_app_id\")" > /dev/null); then
        # exec alacritty --class $term_app_id -e \
        #      tmux new-session -A -s default
        exec foot --app-id $term_app_id \
           tmux new-session -A -s default
    fi
fi