Skip to content

Instantly share code, notes, and snippets.

@dnordstrom
Forked from Vermaak5/kill
Created July 23, 2022 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnordstrom/fe49d9af9f69df31920e9160c00a2753 to your computer and use it in GitHub Desktop.
Save dnordstrom/fe49d9af9f69df31920e9160c00a2753 to your computer and use it in GitHub Desktop.
killwindow
#!/bin/bash
# add to sway config:
# bindsym Mod1+q exec ~/kill.sh
# this script kills the window UNLESS the name matches. If the name matches the SIGTERM signal is send to the target process
# in case of wayland, the attribute 'app_id' is used while X11 windows use 'class'
current_window=$(swaymsg -t get_tree | grep -A 45 '"focused": true' | egrep 'app_id|class' | cut -d \" -f 4 | grep .)
if [[ "$current_window" =~ ^(MYPROCESS|ALTERNATIVENAME)$ ]]; then
swaymsg exec 'pkill --signal SIGTERM -f /usr/bin/MYPROCESS'
else
swaymsg kill
fi
@dnordstrom
Copy link
Author

TODO: Change shebang, make POSIX compliant, add argument for "force quitting," etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment