Blog is moving

My blog is moving to http://victormendonca.com/blog/. If you are looking for a specific or older post you are in the right place Otherwise check out my new page for more up to date content.

Sunday, March 9, 2008

Quick and simple Quake Terminal


For the gamers out there, you know exactly what I'm talking about. I've never been big with gaming, but the idea of having a shortcut to shade a terminal window and bring it back whenever I want is pretty neat.

I already run a small terminal window as part of my desktop, but sometimes its not as flexible as a normal window. I'll write a post on how to use a terminal as a desktop background in the future. For now you can see a pic here.

To achieve what we want we will use a utility called wmctrl, which is on the Ubuntu repos (if I'm not mistaken the Universe repo). There are other ways you can achieve the same (like Tilda).

$ sudo apt-get install wmctrl


wmctrl bases it's commands on window name, so to make sure you have the proper name for the terminal window, open it with the desired profile and type:

$ wmctrl -l
0x03800021 -1 hostname Left
0x03c000cc 0 hostname Jinzora Media Jukebox - Genres - Mozilla Firefox
0x01407084 1 hostname blog - File Browser
0x04400057 1 hostname quake-terminal - OpenOffice.org Writer
0x0380859b 1 hostname victor@hostname: ~


These are the list of windows I have open. My terminal window is called “victor@hostname”, so this is the name I'm going to use. Next, I'll open my favorite text editor and add the following lines to a script:

#!/bin/bash

if [ -f ~/bin/temp/quake ] ; then
wmctrl -r 'victor@hostname: ~' -b remove,below
wmctrl -r 'victor@hostname: ~' -b remove,shaded
rm -r ~/bin/temp/quake
else
wmctrl -r 'victor@hostname: ~' -b add,below
wmctrl -r 'victor@hostname: ~' -b add,shaded
touch ~/bin/temp/quake
fi


Here's a breakdown to make it easy. I have a folder on /home/victor/bin with many scripts I created, so I'll add this one as well, and I called it ter-quake.sh. Next, I created a temp folder inside my bin folder to generate a file that will check if my script was run previously or not. And here's the explanation for the script

#!/bin/bash

## This first line checks if the file /bin/temp/quake was created, which meas the script was run before
if [ -f ~/bin/temp/quake ] ; then
## if the script was run before, it will unshade the terminal window and place it on top
wmctrl -r 'victor@victor-laptop: ~' -b remove,below
wmctrl -r 'victor@victor-laptop: ~' -b remove,shaded
## here we remove the file
rm -r ~/bin/temp/quake

## otherwise, if the file does not exist
else
## the sript will shade the window, place it bellow all others and...
wmctrl -r 'victor@victor-laptop: ~' -b add,below
wmctrl -r 'victor@victor-laptop: ~' -b add,shaded
## create the file
touch ~/bin/temp/quake
fi


Save the script and make it executable:

$ sudo chmod a+x ~/bin/ter-quake.sh


Last step, we will add a keyboard shortcut for the script. I've achieved that by using gnome's gconf-editor:

- Type “Alt+F2” and enter “gconf-editor”
- Browse to “/apps/metacity/keybinding_commands”
- Choose any of the empty commands and add the path to your script
- Go to “/apps/metacity/global_keybindings” and under “run_command_#” add the shortcut you would like to use. I've used q.


Vic.


Note: This is another useful topic from Linux Journal that I wanted to share. Issue 167. Link

No comments: