Allow multiplier for usize.
authorIain Patterson <me@iain.cx>
Wed, 5 Oct 2011 13:38:29 +0000 (14:38 +0100)
committerIain Patterson <me@iain.cx>
Wed, 5 Oct 2011 16:31:40 +0000 (17:31 +0100)
Instead of entering an explicit number of rows or columns to usize,
allow, eg x2 or x3.

opt/bin/usize

index 39d8110..e1751fe 100755 (executable)
@@ -3,6 +3,7 @@
 # usize: Set urxvt (or terminal which understands the same escape sequences) 
 #        size.
 # Usage: usize <width> [<height>]
+# Usage: usize x<width_multiplier> [x<height_multiplier>]
 #
 
 width=${COLUMNS:-80}
@@ -18,6 +19,19 @@ case $# in
   2) width=$1; height=$2;;
 esac
 
+# Allow, eg, x2 for width or height.
+if [ ! "${width#x}" = "${width}" ]; then
+  # Add a column for dividers.
+  width=${width#x}
+  width=$((width-1+(87*width)))
+fi
+if [ ! "${height#x}" = "${height}" ]; then
+  height=${height#x}
+  height=$((24*height))
+  # Add a row for tmux.
+  [ $height -gt 1 ] && height=$((height+2))
+fi
+
 [ -n "$TMUX" ] && tmux_prefix="\033Ptmux;\033"
 echo -e "$tmux_prefix\033[8;$height;$width;t"
 exit 0