Set Window Title in Bash


kirsle
Posted by Noah Petherbridge on Saturday, November 07 2009 @ 03:12:20 AM
Update (Nov 6 09): I found an even better way to do this and it emulates the way it works in DOS.

Just edit your .bashrc file and add this function to it:

# Allow the user to set the title.
function title {
PROMPT_COMMAND="echo -ne \"\033]0;$1 (on $HOSTNAME)\007\""
}
Now you can just do e.g. title IRC or whatever, and it would set the window title to IRC (on aerelon) if your hostname was aerelon like mine is (the hostname is handy if you work with multiple servers).

Now, the original post follows:

This is a small script I wrote that allows you to set a custom window title on your bash shells. It works in most sane bash terminal emulators (gnome-terminal and XFCE's Terminal for sure, Konsole likely, xterm likely...)

It works kinda, sorta like the DOS `title` command, except it doesn't take your title on the command line and instead prompts for it after you run the command.

Installation is in 2 parts:

1) The bash script, which you put in your home directory's "bin" folder (eg /home/kirsle/bin) - make the folder if it doesn't exist.

#!/bin/bash

echo -n "Title: "
read -e TITLE
PROMPT_COMMAND='echo -ne "\033]0;$TITLE\007"'
2) The bash alias. Setting a title manually involves typing that last line (PROMPT_COMMAND) into the terminal directly (with an actual title in place of $TITLE); it sets the environment variable PROMPT_COMMAND, which ensures your custom title sticks. Bash scripts aren't allowed to modify your environment variables by default. So, set an alias to this command that, instead of executing it, sources it instead.

Edit your .bashrc file (eg. /home/kirsle/.bashrc):

alias title='. /home/kirsle/bin/title'
Now reload your .bashrc file with the command `. ~/.bashrc` or start a new bash shell, type in the word `title` and hit enter, and enter a title when prompted.

Categories:

[ Blog ]

Comments

There are 2 comments on this page.

guest
guest
Posted on Thursday, August 06 2009 @ 07:11 PM by tomekzet.

Simple and useful :)

guest
guest
Posted on Sunday, January 24 2010 @ 04:52 PM by Kuky.

I just like to say that this page looks very nice and that I am amazed that is strict.dtd!
Thanks

Add a Comment

Your name:
Your Email: (optional)
Message:
You can use emoticons in your comment. (opens in a new window)

If you can see this, don't touch the following fields.


Kirsle
» Homepage (RSS)
» About Me
» Photo Albums
» Guestbook
» Contact Me
Channels
» Linux (48)
» General (46)
» Perl (34)
» Rant (22)
» Software (15)
» HowTo (11)
» RiveScript (9)
» Minecraft (9)
» Gnome 3 (8)
» Android (8)
» Windows (8)
» Curiosity (7)
» HTML (7)
» Siikir (7)
» Design (6)
» Tk (6)
» Gay (5)
» Java (4)
» Blackhat (4)
» Reviews (4)
» VirtualBox (4)
» Ideas (3)
» DOS (3)
» Photos (3)
» KAGE (3)
» Xfce (3)
» ttf2eot (3)
» Licensing (3)
Creativity
» 3D Renderings
» Flash Animation
» JavaScript
» Fonts
» Metacity
» Tutorials
Software
» RiveScript
» Error Generator
» Tk Calculator
» Terminal Apps
» CyanChat Client
Web Tools
» TTF to EOT
» Text Fader
» Favicons
» Distance Calc
» Azulian Encoder
» XBM Masks
Subdomains
» Shell Scripts
» Linux RPMs
» Rophako CMS
» Kirsle::Nano
» Minecraft Server
Miscellany
¤ Pokemon Fuchsia City
¤ DOS and Windows
¤ Raspberry Pi
Links
¤ Google+
¤ Facebook
¤ Twitter
¤ MySpace
¤ Github
¤ CPAN
Fan Club
» Log In