#!/bin/bash

# Synopsis:	Simple wrapper script for ratpoisons "swap" feature
# Author:		thims (root DOT packet AT gmail DOT com)
# Date:			20090309
# Comments:	

# A simple wrapper script to give ratpoisons "swap" command the 
# ability to automatically swap frames if only 2 frames are open.


frames=$(( $(ratpoison -c sfdump | sed 's/,/\n/g' | wc -l) - 1)) # minus 1 due to the trailing , in sfdump
framenum=( )
cnt=0

for i in $(ratpoison -c sfdump | sed 's/,/\n/g' | awk '{print $3}')
do 
	framenum[$cnt]=$i
	cnt=$((cnt + 1))
done

if [ $frames == 2 ] ;then
	ratpoison -c "swap ${framenum[0]} ${framenum[1]}"
elif [ $frames -lt 2 ] ;then
	exit 0
else
	ratpoison -i -c swap
fi	
