Skip to content

Instantly share code, notes, and snippets.

@Scoder12
Created January 4, 2023 05:50
Show Gist options
  • Save Scoder12/aa2ce65f4b0892b88d2830332b0b9424 to your computer and use it in GitHub Desktop.
Save Scoder12/aa2ce65f4b0892b88d2830332b0b9424 to your computer and use it in GitHub Desktop.
i3-resurrect saver
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