-
Notifications
You must be signed in to change notification settings - Fork 3
/
xdie
executable file
·36 lines (29 loc) · 995 Bytes
/
xdie
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
#!/bin/bash
# Kills processes based on their window title.
if [[ $1 == "-p" ]]; then
PRETEND=1
shift
fi
if [[ -z $* ]] || echo "$*" | grep -Eq -- '--help\b|-h\b'; then
echo "usage: $(basename "$0") [-p|-h|--help] REGEX"
echo "Kills all windows matching REGEX. Use -p for pretend mode."
exit 1
fi
# shellcheck source=.shell_control
# shellcheck disable=SC1091
source "$HOME/.shell_control" || echo "$(tput bold)error: ~/.shell_control not installed!$(tput sgr0)" >&2
LIST="$(xlsclients -l | grep -E '^Window 0x([0-9]|[a-z])*:$|^\W*Name:\W*.*$' | sed 'N;s/:\n/ /g' | grep "$1")"
if [[ $LIST == "" ]]; then
show "no windows found"
exit 0
fi
show "$(echo "$LIST" | wc -l) windows found:"
show "$LIST"
if [[ -z $PRETEND ]]; then
show "Killing windows... "
run "echo '$LIST' | awk '{print $2}' | xargs -I{} xkill -id {}"
else
show "Pretending to kill windows... "
run "echo '$LIST' | awk '{print $2}' | xargs -I{} echo "xkill -id {}""
fi
show "done"