Monday, September 22, 2014

Tip: Setting terminal tab name in Mac

Just a quick tip ...

My development environment tends to consist of a set of terminal windows and a text editor (currently Sublime Text).  Rather right clicking on each terminal tab to give it a name I wanted to set it from the command line.

That way I can open new tabs with Ctl-+, and then keep them organized. By placing the following script in /usr/local/bin

#!/bin/bash
#********************************************************************************
# Copyright 2014 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
#********************************************************************************
# Sets name of the maxOS terminal
usage()
{
echo "Usage: `basename $0` nameOfWindow"
echo ""
echo "Sets the name of the terminal window on your mac"
echo ""
}
if [ "$#" == "1" ]; then
echo "setting name of tab to $1"
echo -n -e "\033]0;$1\007"
else
echo "incorrect arguments"
usage
fi
view raw setName.sh hosted with ❤ by GitHub
This script can be run to setup the title. For example:
Robbie-2014-MacBook-Pro:foo robbie$ git clone https://gist.github.com/d3bc496f01f6221ec0a1.git
Cloning into 'd3bc496f01f6221ec0a1'...
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
Robbie-2014-MacBook-Pro:foo robbie$ ls
d3bc496f01f6221ec0a1
Robbie-2014-MacBook-Pro:foo robbie$ cd d3bc496f01f6221ec0a1/
Robbie-2014-MacBook-Pro:d3bc496f01f6221ec0a1 robbie$ sudo cp setName.sh /usr/local/bin/title
Password:
Robbie-2014-MacBook-Pro:d3bc496f01f6221ec0a1 robbie$ sudo chmod +x /usr/local/bin/title
Password:
Robbie-2014-MacBook-Pro:d3bc496f01f6221ec0a1 robbie$ title foo
setting name of tab to foo
view raw usingSetName hosted with ❤ by GitHub

For some other useful tips on using terminal such as setting the theme on the command line check out:

No comments:

Post a Comment