Copy became script to target directory.
[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 # Usage: usize X<multiplier>
8 #
9
10 width=${COLUMNS:-80}
11 height=${LINES:-24}
12 tmux_prefix=
13
14 case $# in
15   0)
16     echo "Usage: usize $width $height"
17     exit 1
18   ;;
19   1) width=$1;;
20   2) width=$1; height=$2;;
21 esac
22
23 # Allow, eg, x2 for width or height.
24 if [ ! "${width#X}" = "$width" ]; then
25   width="${width/X/x}"
26   height=$width
27 fi
28 if [ ! "${width#x}" = "$width" ]; then
29   # Add a column for dividers.
30   width=${width#x}
31   width=$((width-1+(87*width)))
32 fi
33 if [ ! "${height#x}" = "$height" ]; then
34   height=${height#x}
35   height=$((24*height))
36   # Add a row for tmux.
37   [ $height -gt 1 ] && height=$((height+2))
38 fi
39
40 [ -n "$TMUX" ] && tmux_prefix="\033Ptmux;\033"
41 echo -en "$tmux_prefix\033[8;$height;$width;t"
42 exit 0