-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm-workspace-kill
executable file
·63 lines (53 loc) · 2.07 KB
/
wm-workspace-kill
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
# SCRIPT_DIR is set to the directory where this script is localed. It it was
# run by a symlink, it will be resolved to the directory of the target script
# (that is, the actual script directory).
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [[ -L "${BASH_SOURCE[0]}" ]]; then
SCRIPT_DIR="$(readlink "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$( cd "$( dirname "${SCRIPT_DIR}" )" >/dev/null 2>&1 && pwd )"
fi
# wm-workspace-kill
# - close all windows in a workspace (but leave floating ones)
# get platform info, populates 'platform' and 'apple_silicon' variables
source "${SCRIPT_DIR}"/lib/platform.sh
shopt -s xpg_echo
bold="\033[1m"
green="\033[32m"
reset="\033[0m"
# print usage with -h/--help
if [[ "$#" -eq 1 && ("$1" == "-h" || "$1" == "--help") ]]; then
echo "${bold}Usage:${reset} ${green}wm-workspace-kill${reset} [workspace-name]"
echo " - Close all windows in the provided workspace (but leave floating ones)"
echo " - If no workspace is provided, uses the currently focused workspace"
exit 0
fi
current_workspace=$(wm-workspace-get-current)
if [[ "$#" -eq 0 ]]; then
workspace="$current_workspace"
else
workspace="$1"
fi
if [[ "$platform" == "macos" ]]; then
# find pids of all windows with "has-focus" set to false in the current workspace
non_focused_window_pids=$(yabai -m query --windows --space | jq -r '.[] | select(."has-focus"==false) | .pid')
# get PID of every window and kill it
for pid in $non_focused_window_pids; do
kill -9 $pid
done
# finally, kill the current window
window_pid=$(yabai -m query --windows --window | jq -r '.pid')
kill -9 $window_pid
echo "Closed all windows in all workspaces"
exit
else
windows=$(swaymsg -t get_tree | jq -r --arg workspace "$workspace" '.nodes[].nodes[] | select(.name==$workspace) | .nodes[].id')
for window in $windows; do
swaymsg '[con_id='$window'] kill'
done
fi
message="Killed all windows in workspace ${bold}$workspace${reset}"
if [[ "$workspace" == "$current_workspace" ]]; then
message="$message (current)"
fi
echo "$message"