Skip to content

Instantly share code, notes, and snippets.

@hellwolf
Created September 5, 2023 20:41
Show Gist options
  • Save hellwolf/6d2b6c6d61260808cc8af6ed69764025 to your computer and use it in GitHub Desktop.
Save hellwolf/6d2b6c6d61260808cc8af6ed69764025 to your computer and use it in GitHub Desktop.
Toogle sticky gnome terminal
#!/usr/bin/env bash
# Usage: toggle-sticky-terminal.sh [above|below]
set -x
STATUS_FILE=$XDG_RUNTIME_DIR/sticky-terminal-status.json
setup() {
gnome-terminal --profile=scratchpad
_WIN=$(wmctrl -l | tail -n1 | awk '{ print $1 }')
_POS=below
}
cleanup() {
[ "$?" != 0 ] && rm -f "$STATUS_FILE"
}
trap cleanup EXIT
if _WIN=$(jq -r .win "$STATUS_FILE"); then
_POS=$(jq -r .pos "$STATUS_FILE")
else
setup
fi
if ! wmctrl -l | grep "$_WIN";then setup;fi
# Anything fail onwards trigger a reset
set -e
wmctrl -ir "$_WIN" -b add,sticky
if [ "$_POS" = below ] || [ "$1" == above ]; then
_POS=above
wmctrl -ir "$_WIN" -b add,above
xdotool windowactivate "$_WIN"
else
wmctrl -ir "$_WIN" -b remove,above
xdotool windowminimize "$_WIN"
_POS=below
fi
echo "{ \"win\": \"$_WIN\", \"pos\": \"$_POS\" }" > "$STATUS_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment