LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Terminal titles, KDE, Gnome etc... (https://www.linuxquestions.org/questions/linux-software-2/terminal-titles-kde-gnome-etc-135413/)

clar77 01-16-2004 09:45 AM

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.

Thanks

hw-tph 01-16-2004 10:44 AM

Set the environment variable $PROMPT_COMMAND. In my ~/.bashrc (which is sourced from .bash_profile so it's always set) I have this:
Code:

# Change the window title of X terminals
case $TERM in
        xterm*|rxvt|Eterm|eterm|aterm)
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
                ;;
        screen)
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
                ;;
esac


Håkan

clar77 01-16-2004 12:52 PM

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.

fvu 12-21-2007 12:58 PM

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

PROMPT_COMMAND
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:
Code:

# 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:
# http://fvue.nl/wiki/NameTerminal
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: http://fvue.nl/wiki/Bash:_Change_dir...o_project:_cdp

Freddy Vulto
http://fvue.nl


All times are GMT -5. The time now is 07:33 PM.