Created
September 13, 2012 16:47
-
-
Save c00kiemon5ter/3715709 to your computer and use it in GitHub Desktop.
script to toggle visibility of a terminal
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rxvt-unicode offers a daemon that handles client instances of
urxvt
.The daemon is
urxvtd
and the clients areurxvtc
.Using the daemon/client scheme is much cheaper in terms of resource usage (mainly memory).
To use
urxtvtc
replaceurxvt
on line 22 withurxvtc
.Also check
urxvtdc
to safely spawn client instances ofurxvt
.