Resizing Your Terminal

Posted by Doug Fri, 05 Oct 2007 12:24:00 GMT

I thought I’d go ahead and publish this because I found it useful (if ugly). I do a lot of remote pair programming where my partner and I share a multi-user screen session inside a terminal. It’s very important that both partners have the same number of columns and rows visible. Otherwise, whoever is smaller isn’t going to see everything the other person sees and stuff jumps around and it’s generally annoying.

So, the first thing that happens when you start a remote pairing session is you negotiate screen size. I have my Apple Terminal.app set to show the screen size in the title bar as something like 105×54 or 94×71 or whatever. So when my partner says, “I can do 120×62 as my maximum size” I have to click and drag my Terminal window until my size matches. No more!

As I said above, this is pretty ugly but it works. This shell script makes a one line applescript call through osascript to tell the Terminal what size to make the window. I put it in a shell script like this to simplify calling. I started with a straight up applescript, but it was ugly to call it from the command line. So I converted it to what you see here:

#!/bin/sh /usr/bin/osascript -e 'tell application "Terminal"' -e "tell front window" -e "set the number of rows to $2" -e "set the number of columns to $1" -e "end tell" -e "end tell"

You can invoke it by simply saying:

$ resize_terminal 94 71

and the front most Terminal window (likely the one you’re typing in) will resize to 94 rows tall by 71 columns wide.

Posted in ,  | Tags , , ,  | 2 comments

Comments

  1. Rob Biedenharn said about 2 hours later:
    Or in ruby with the Ruby-OSA bridge:
    
    begin
      require 'rubygems'
      require 'rbosa'
    rescue LoadError
      puts "Unable to load 'rbosa', the Ruby-OSA bridge.\n  sudo gem install rbosa" 
      exit
    end
    
    term = OSA.app 'Terminal'
    
    if frontwindow = term.windows.detect{|w|w.frontmost?}
      suppress_display = frontwindow.title_displays_window_size?
      if ARGV.size >= 2
        cols, rows = ARGV[0..1].map{|a|a.to_i}
        frontwindow.number_of_columns = cols
        frontwindow.number_of_rows    = rows
        suppress_display = false
      end
      puts "#{frontwindow.number_of_columns}x#{frontwindow.number_of_rows}" unless suppress_display
    else
      puts "no frontmost window?" 
    end
    
  2. Dave Minor said about 5 hours later:

    you’re much more savvy than I, but my poor man’s version:

    right click -> window settings select Window set width/height click in other window set width/height

Comments are disabled

Copyright 2001 - 2005 by Lathi.net and Doug Alcorn

Creative Commons, Some Rights Reserved Ruby on Rails Developer Powered by Debian GNU/Linux Powered by Typo