Skip to content

Instantly share code, notes, and snippets.

@c00kiemon5ter
Created September 13, 2012 16:47
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save c00kiemon5ter/3715709 to your computer and use it in GitHub Desktop.
script to toggle visibility of a terminal
#!/bin/sh
name="scratchpad"
class="URxvt"
# print the window id of the window with the given
# instance name as the first argument '$1' and
# class name as the second argument '$2'
get_win_id() {
xwininfo -root -children -int | awk -v n="$1" -v c="$2" '$3 == "(\""n"\"" && $4 == "\""c"\")" { print $1 }'
}
# get the window id
winid="$(get_win_id "$name" "$class")"
# if the window was not found
if [ -z "$winid" ]
then
# spawn it
urxvt -name "$name"
# get the window id again
winid="$(get_win_id)"
# if the window was not found then something is really wrong. give up.
[ -z "$winid" ] && exit 1
fi
# if the window is hidden show it, else hide it
if ! xwininfo -id "$winid" | awk '$1 == "Map" && $2 == "State:" { exit ($3 == "IsUnMapped") }'
then xdotool windowmap "$winid"
else xdotool windowunmap "$winid"
fi
@c00kiemon5ter
Copy link
Author

Rxvt-unicode offers a daemon that handles client instances of urxvt.
The daemon is urxvtd and the clients are urxvtc.
Using the daemon/client scheme is much cheaper in terms of resource usage (mainly memory).

To use urxtvtc replace urxvt on line 22 with urxvtc.

Also check urxvtdc to safely spawn client instances of urxvt.

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