Categories

Our Sponsors

Unix Terminal Headers and Titles

Please see another post of mine about terminal colors if this post is a little confusing.

Add the following to your .kshrc or .bashrc files.

# KSH terminal headers add to .profile
PS1=`uname -n`” $ ”
alias cd=_cd
function _cd {
\cd ${1+”$@”} && echo “\033]0;${USER}@${HOST}: ${PWD}\007\c”
}

# BASH terminal headers add to .bashrc
PROMPT_COMMAND=’echo -ne “\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007″‘
# PS1=’\h] \w\$ ‘ #simple prompt with hostname and current path
PS1=’\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]‘ #color prompt

More detailed historic type information.

So you want the title bar to look different in you xterm or terminal window?

This also works for Putty terminal windows.

echo -n ^[]1\;$icon_name\^G^[]2\;$HOSTNAME\: $cwd\^G’

Two small changes will be necessary after this text is cut & pasted.
Replace the “^[" and "^G" characters with esc and CNTL-G by typing [ctrl-v][esc] and [ctrl-v][ctrl-g].

You can set up an alias

alias mytitle ‘icon_name; echo -n ^[]1\;$icon_name\^G^[]2\;$HOSTNAME\: $cwd\^G’

Then set an alias to change your prompt and title

alias cd ‘chdir \!*;set prompt=”`dirs`#\\!% “; mytitle’

Another way of stating this is:
Window and icon titles may be changed in a running xterm by using XTerm escape sequences. The following sequences are useful in this respect:

ESC]0;stringBEL — Set icon name and window title to string
ESC]1;stringBEL — Set icon name to string
ESC]2;stringBEL — Set window title to string
where ESC is the escape character (\033), and BEL is the bell character (\007).

echo -n “\033]0;${USER}@${HOST}\007″

should produce a title like username@hostname, assuming the shell variables $USER and $HOST are set correctly.

—-

I found the following also works very well.

Add these lines to your .profile for KSH or .bashrc for BASH and just uncomment the KSH or BASH line.

function _cd {
# KSH terminal headers
# \cd ${1+”$@”} && echo “\033]0;${USER}@${HOST}: ${PWD}\007\c”
# BASH terminal headers
# \cd ${1+”$@”} && echo -ne “\033]0;${USER}@${HOST}: ${PWD}\007″
}

alias cd=_cd

# Cool Colored prompt for BASH Shells it shows user@host and Present directory, but not the whole PATH.
# PS1=’\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]‘

I also like to add the following to my .bashrc so that I can use VI type commands
set -o vi

Share

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes