Skip to content

Instantly share code, notes, and snippets.

@mfiers
Created April 12, 2012 21:32
Show Gist options
  • Save mfiers/2371139 to your computer and use it in GitHub Desktop.
Save mfiers/2371139 to your computer and use it in GitHub Desktop.
Bash script for a Quake type terminal
#!/bin/bash
# (c) Mark Fiers
# Released under GPLv3
# Simple bash script to have a quake like terminal
# Bind this script to any key in your WM config
#
# works with openbox, but should work with any EWMH/NetWM compliant
# window manager
#
# Hard coding gnome-terminal & tmux - but that is easily changed.
# Note - I've set up a specific profile for the quake window - so it
# it easily recognizable. You MUST make sure that gnome-terminal (or any
# emulator) does NOT change the window title - this script relies on there
# being (just one) window titled quake.
#first - is the window already active?
quake_term_active=`wmctrl -l | grep 'quake$'`
if [[ -z "${quake_term_active}" ]]
then
# no quake terminal - start one
gnome-terminal --profile=quake -t quake -e 'tmux attach'
wmctrl -t quake add,above,skip_taskbar
#determine terminal width - and set dimensions
screen_width=`(xrandr 2>/dev/null) | grep '*' 2>/dev/null | cut -f 1 -d'x'`
if [[ "$screen_width" -gt 2500 ]]
then
# if terminal width >> 2500 - assume it is a dual screen setup
# halve the size
screen_width=$(($screen_width/2))
fi
wmctrl -l
wmctrl -r quake -e 0,1,20,${screen_width//[[:space:]]},400
exit 0
fi
#check if the terminal is on the current desktop
current_desktop=`wmctrl -d | grep '*' | cut -f 1 -d' '`
#desktop where the quake window resides
quake_desktop=`wmctrl -l | grep 'quake$' | cut -c12-14`
if [[ "$current_desktop" -eq "$quake_desktop" ]]
then
# the window is on the current desktop
# figure out if the quake window is active (cannot do that with wmctrl??!)
active_window_id=`xprop -root | grep '^_NET_ACTIVE_WINDOW' | cut -f2 -d#`
quake_window_id=`wmctrl -l | grep 'quake$' | cut -f 1 -d' '`
if [[ "$(($active_window_id))" -eq "$(($quake_window_id))" ]]
then
#window is active and on this desktop - hide
wmctrl -r quake -b add,hidden
else
# window is not active and on this desktop - hide
wmctrl -r quake -b remove,hidden
wmctrl -R quake
fi
else
#quake window is on another desktop - get it & display
wmctrl -r quake -b remove,hidden
wmctrl -R quake
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment