Mild OCD.
[profile.git] / opt / bin / usize
1 #!/bin/bash -i
2 #
3 # usize: Set urxvt (or terminal which understands the same escape sequences) 
4 #        size.
5 # Usage: usize <width> [<height>]
6 # Usage: usize x<width_multiplier> [x<height_multiplier>]
7 #
8
9 width=${COLUMNS:-80}
10 height=${LINES:-24}
11 tmux_prefix=
12
13 case $# in
14   0)
15     echo "Usage: usize $width $height"
16     exit 1
17   ;;
18   1) width=$1;;
19   2) width=$1; height=$2;;
20 esac
21
22 # Allow, eg, x2 for width or height.
23 if [ ! "${width#x}" = "${width}" ]; then
24   # Add a column for dividers.
25   width=${width#x}
26   width=$((width-1+(87*width)))
27 fi
28 if [ ! "${height#x}" = "${height}" ]; then
29   height=${height#x}
30   height=$((24*height))
31   # Add a row for tmux.
32   [ $height -gt 1 ] && height=$((height+2))
33 fi
34
35 [ -n "$TMUX" ] && tmux_prefix="\033Ptmux;\033"
36 echo -en "$tmux_prefix\033[8;$height;$width;t"
37 exit 0