Rahul
Rahul

Reputation: 11669

How to get the the current hostname as the title of your terminal

I want to get the hostname of the remote system i connect to as the title of my terminal. I have a simple setting done in my bash_profile , which is populated in all the systems where i login.

I am using this script as of now

PS1='[\u@\h:\w]\$ '
export TITLEBAR='\[\033]0;\u@\h:\w \007\]'

# Terminal sets TERM_PROGRAM so we can tell it apart from regular VT100
case "$TERM_PROGRAM" in
"Apple_Terminal")PS1="$TITLEBAR$PS1"
esac
case "$TERM" in
"xterm")PS1="$TITLEBAR$PS1"
esac
# end insert

The problem is when i logout from a remote system , i am not able to get my current system(hostname details) in the terminal title.

Upvotes: 0

Views: 2793

Answers (2)

Xupeng
Xupeng

Reputation: 371

I am using this one:

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'

add it in $HOME/.bash_profile on both local machine and remote machines.

Upvotes: 3

John3136
John3136

Reputation: 29266

Make all of that a little bash function and then call that bash function manually when you logout of a remote system?

Upvotes: -1

Related Questions