Created
January 4, 2023 05:50
-
-
Save spencerpogo/aa2ce65f4b0892b88d2830332b0b9424 to your computer and use it in GitHub Desktop.
i3-resurrect saver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shouldmatchtitle () { | |
case "$1" in | |
discord | VSCodium) | |
return 0 | |
;; | |
*) | |
return 1 | |
;; | |
esac | |
} | |
main () { | |
local lastitle= | |
local windowprops | |
local title | |
local class | |
while true; do | |
if [ -n "$ZSH_VERSION" ]; then | |
windowprops=(${(f)"$(xdotool getwindowfocus getwindowname getwindowclassname)"}) | |
title="${windowprops[1]}" | |
class="${windowprops[2]}" | |
else | |
readarray -t windowprops < <(xdotool getwindowfocus getwindowname getwindowclassname) | |
title="${windowprops[0]}" | |
class="${windowprops[1]}" | |
fi | |
printf 'Title: %s\nClass: %s\n' "$title" "$class" | |
if [[ "$title" != "$lasttitle" ]]; then | |
num="$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused == true) | .num')" | |
cmd=("i3-resurrect" "save") | |
shouldmatchtitle "$class" | |
if [[ "$?" -eq 1 ]]; then | |
cmd+=("--swallow=class,instance,title") | |
fi | |
cmd+=("--numeric" "--workspace" "$num") | |
# print the command | |
printf '%s ' "${cmd[@]}" | |
printf '\n' | |
# run the command | |
"${cmd[@]}" & | |
fi | |
lasttitle="$title" | |
sleep 0.25 | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment