#! /bin/sh usage() { echo "Usage:" echo " `basename $0` \"title\" to provide a new Terminal title." echo " `basename $0` -h to set the hostname as the Terminal title." } help0() { echo "ERROR: No argument provided." usage; } help2() { echo "ERROR: Too many arguments provided." usage; } if [ $# -eq 0 ] then help0; elif [ $# -eq 1 ] then if [ "$1" == "-h" ] then windowname=`hostname | sed "s/\.home//" | sed "s/\.local//" | sed "s/\.fios-router//" `; else windowname=$1; fi echo "\033]0;$windowname\007\c"; # The following alternative approach is a bad idea. # It changes all Terminal windows, including future Terminal windows, # even if you close all Terminal windows, Quit from Terminal and launch # a new Terminal window. # osascript -e "tell application \"Terminal\" to set custom title of window 1 to \"$1\"" elif [ $# -gt 1 ] then help2; fi