Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-16-2004, 09:45 AM   #1
Registered: May 2002
Location: Baltimore,MD
Distribution: RH8.0 FC1/2.6.1 MacOsX 10.3
Posts: 53

Rep: Reputation: 15
Terminal titles, KDE, Gnome etc...

Just an informational sort of question here:

Does anyone know how the current working dir is displayed at the top of the terminal window in some terminal applications ? I know that it can be done with $PS1 at the prompt in bash but how is it constantly updated and sent to the terminal app ?

is some variable set to $pwd and updated with each call of cd ?

I'm curious because I've been playing with aterm and eterm on my mac and linux boxes and was sondering how to get these apps to display a similar window title.

Old 01-16-2004, 10:44 AM   #2
Senior Member
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
Set the environment variable $PROMPT_COMMAND. In my ~/.bashrc (which is sourced from .bash_profile so it's always set) I have this:
# Change the window title of X terminals 
case $TERM in
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'

Old 01-16-2004, 12:52 PM   #3
Registered: May 2002
Location: Baltimore,MD
Distribution: RH8.0 FC1/2.6.1 MacOsX 10.3
Posts: 53

Original Poster
Rep: Reputation: 15
Thanks that worked great!

So its actually written into the various terminal apps to call that variable each time the directory changes and update the title bar accordingly ?

Thanks again.
Old 12-21-2007, 12:58 PM   #4
LQ Newbie
Registered: Nov 2006
Distribution: Ubuntu 7.10
Posts: 28

Rep: Reputation: 15
Yes, it is called each time. From `info bash':

If set, the value is executed as a command prior to issuing each primary prompt.

Alternatively, you can use a bash function `nameTerminal' like this:
# Set terminal title
# @param string $1  Tab/window title
# @param string $2  (optional) Separate window title
# The latest version of this software can be obtained here:
function nameTerminal() {
    [ "${TERM:0:5}" = "xterm" ]   && local ansiNrTab=0
    [ "$TERM"       = "rxvt" ]    && local ansiNrTab=61
    [ "$TERM"       = "konsole" ] && local ansiNrTab=30 ansiNrWindow=0
        # Change tab title
    [ $ansiNrTab ] && echo -n $'\e'"]$ansiNrTab;$1"$'\a'
        # If terminal support separate window title, change window title as well
    [ $ansiNrWindow -a "$2" ] && echo -n $'\e'"]$ansiNrWindow;$2"$'\a'
} # nameTerminal()
This way, you can set the title manually, whenever you like. Personally, I find it useful the set the title when I change to a project directory only. I've written a `cdp' utility for that; you could put `nameTerminal' in the .cdprc file. See:

Freddy Vulto


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Xserver has only failsafe terminal on FC2 gnome and KDE gone sueno Fedora 2 04-10-2005 09:29 PM
CLI to Gnome terminal, in KDE.? Carpinus Linux - Newbie 11 03-08-2005 10:56 AM
Alternative terminal to konsole & gnome-terminal Adony Linux - Software 3 10-08-2004 03:59 AM
KDE konsole - Gnome-terminal language encoding or keytab thk33 Linux - Software 3 09-19-2004 03:59 PM
How do I log-out from KDE or Gnome using the Terminal Riichard Linux - Newbie 1 07-07-2004 08:27 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:54 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration