snap your window to the left or right

This script will snap your window to the left or right side of the screen in Linux: (SOURCE)

#!/bin/sh
## ${HOME}/bin/wmctrl-snap-edge
#DTPD#
WMCTRL="${HOME}/bin/wmctrl_`arch`"
#WMCTRL="/usr/bin/wmctrl"
test -x "/usr/bin/xdpyinfo" -a -x "$WMCTRL" || {
    echo "error"; exit 1; }

WIDTH=`xdpyinfo | sed -n 's/ *dimensions: *\([0-9]*\)x.*/\1/p'`
HALF=$(($WIDTH / 2));
"$WMCTRL" -r :ACTIVE: -b add,maximized_vert;
if test "$1" = "left" ; then
	"$WMCTRL" -r :ACTIVE: -e 0,0,0,$HALF,-1
elif test "$1" = "right" ; then
	"$WMCTRL" -r :ACTIVE: -e 0,$HALF,0,$HALF,-1
fi

If you don't have wmctrl installed, you can apt-get it (Ubuntu):

sudo apt-get --yes install wmctrl

Or compile it yourself:

sudo yum install libXmu-devel
cd /tmp
wget 'http://tomas.styblo.name/wmctrl/dist/wmctrl-1.07.tar.gz'
tar --extract --gzip --file "wmctrl-1.07.tar.gz"
cd wmctrl-1.07
./configure
make -j 4
mv wmctrl ${HOME}/bin/wmctrl_`arch`

The next step is to set up hotkeys. If you use Metacity like I do, then:

gconftool-2 --type string --set \
	/apps/metacity/global_keybindings/run_command_6 \
	'<Ctrl><Alt>Page_Up'

gconftool-2 --type string --set \
	/apps/metacity/keybinding_commands/command_6 \
	"${HOME}/bin/wmctrl-snap-edge left"

gconftool-2 --type string --set \
	/apps/metacity/global_keybindings/run_command_7 \
	'<Ctrl><Alt>Page_Down'

gconftool-2 --type string --set \
	/apps/metacity/keybinding_commands/command_7 \
	"${HOME}/bin/wmctrl-snap-edge right"