Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Set your xterm/konsole/other terminal title
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
phong
Bodhisattva
Bodhisattva


Joined: 16 Jul 2002
Posts: 778
Location: Michigan - 15 & Ryan

PostPosted: Thu Oct 10, 2002 9:04 pm    Post subject: Set your xterm/konsole/other terminal title Reply with quote

I put this in my /etc/profile:
Code:
if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]
then
        if [ "$TERM" = 'xterm' ]
        then
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
        fi
fi

Works quite nicely so I know where all my terminals are at from the taskbar.
_________________
"An empty head is not really empty; it is stuffed with rubbish. Hence the difficulty of forcing anything into an empty head."
-- Eric Hoffer
Back to top
View user's profile Send private message
kaffee
n00b
n00b


Joined: 23 Nov 2002
Posts: 1

PostPosted: Sat Nov 23, 2002 12:19 pm    Post subject: Reply with quote

Zsh users can utilize precmd() to achieve the same. For example:

Code:

if [ $TERM = xterm ]; then
  precmd () {
    print -Pn "\e]0;[ %/ ]\a"
  }
fi
Back to top
View user's profile Send private message
buckminst
n00b
n00b


Joined: 18 Jul 2002
Posts: 22
Location: Idaho

PostPosted: Thu Jan 16, 2003 1:06 pm    Post subject: title changing with non-xterm terms Reply with quote

It should be noted that some terminal emulators don't identify themselves as 'xterm'... case in point being aterm... you would need to modify the code thusly:

Code:

if [ "$TERM" = 'xterm' ] || [ "$TERM" = 'rxvt' ]


Everything else would be the same.
_________________
Curtis Hogg [ buckminst at inconnu dot islug dot org ]

Sattinger's Law: "It works better if you plug it in!"
This post sponsored by: Frungy, the sport of kings!

Registered Linux User #202758 Sept/1997
Back to top
View user's profile Send private message
itsr0y
Tux's lil' helper
Tux's lil' helper


Joined: 22 Dec 2002
Posts: 81

PostPosted: Fri Jan 17, 2003 7:02 am    Post subject: Reply with quote

kaffee wrote:
Zsh users can utilize precmd() to achieve the same.

In fact, with zsh, you can set the term title to be the path when you are at a prompt, and to the current command when a program is running:
Code:
case $TERM in
     *xterm*|rxvt|(dt|k|E)term)
          precmd () { print -Pn "\e]0;$TERM - %~\a" }
          preexec () { print -Pn "\e]0;$TERM - $1\a" }
          ;;
esac

You can modify the $TERM - %~ and $TERM - $1 as needed. See http://www.acm.uiuc.edu/workshops/zsh/prompt/escapes.html for a full list of stuff to put in the prompt (or title).
Back to top
View user's profile Send private message
barmaley
n00b
n00b


Joined: 26 Nov 2002
Posts: 36

PostPosted: Mon Feb 03, 2003 2:50 am    Post subject: Reply with quote

This version will substitute user's home directory with a tilde:

Code:
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
Back to top
View user's profile Send private message
vbenares
Apprentice
Apprentice


Joined: 13 Aug 2003
Posts: 205

PostPosted: Fri Sep 12, 2003 7:00 pm    Post subject: Reply with quote

I recognize this thread is dead, but . . .

Is there any way to identify in the title bar whether one has su'ed or not?
Back to top
View user's profile Send private message
barmaley
n00b
n00b


Joined: 26 Nov 2002
Posts: 36

PostPosted: Fri Sep 12, 2003 8:39 pm    Post subject: Reply with quote

Of course! If you do 'su -', the version above will display root@host. However, if you do su without '-', it won't, because bash profile is not sourced and $USER contains the old value.

If it's not enought, you have at least the following two possibilities:
- insert `whoami` instead of ${USER}
- place a condition in your .bashrc and set custom PROMPT_COMMAND depending on the value of `whoami`, like this:

Code:

case `whoami` in
    root)
        PROMPT_COMMAND='echo -ne "\033]0;---root---\007"'
        ;;
    *)
        PROMPT_COMMAND='echo -ne "\033]0;---non-root---\007"'
        ;;
esac


This is the code from my real bash config:
Code:

case `whoami` in
    root)
        USER_AT_HOST="# ${USER}@${HOSTNAME%%.*}"
        ;;
    *)
        USER_AT_HOST="${USER}@${HOSTNAME%%.*}"
        ;;
esac

case $TERM in
    xterm*|rxvt|eterm)
        PROMPT_COMMAND='echo -ne "\033]0;${USER_AT_HOST}: ${PWD/$HOME/~}\007"'
        ;;
    screen)
        PROMPT_COMMAND='echo -ne "\033_${USER_AT_HOST}: ${PWD/$HOME/~}\033\\"'
        ;;
esac
Back to top
View user's profile Send private message
vbenares
Apprentice
Apprentice


Joined: 13 Aug 2003
Posts: 205

PostPosted: Sat Sep 13, 2003 1:29 am    Post subject: Reply with quote

This is totally cool.
Back to top
View user's profile Send private message
ed0n
l33t
l33t


Joined: 23 Apr 2003
Posts: 638
Location: Prishtine/Kosove

PostPosted: Sat Sep 13, 2003 7:51 am    Post subject: Reply with quote

in gnome-terminal which I use is to easy and simple to change it , you can change it by change-ing the profile .
But sometimes I also use xterm and this looks cool

thank you phong
Back to top
View user's profile Send private message
shm
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2380
Location: Atlanta, Universe

PostPosted: Thu Oct 02, 2003 4:09 am    Post subject: Reply with quote

with konsole, you can even set the name of the tab using dcop:
I use this:

Quote:
A="$PWD"
PROMPT_COMMAND='echo -ne $A; dcop $KONSOLE_DCOP_SESSION renameSession $A'



I also put this in .vimrc to set the tab to vim's current file
Code:

autocmd BufReadPost * :silent !dcop $KONSOLE_DCOP_SESSION renameSession %

_________________
what up
Back to top
View user's profile Send private message
varnyu
n00b
n00b


Joined: 23 Aug 2002
Posts: 16

PostPosted: Sat Dec 13, 2003 11:57 am    Post subject: displaying current process Reply with quote

hi,

is there any solution for displaying the current running process in the titlebar using bash? (like emerge does)

thanks
Back to top
View user's profile Send private message
kernelcowboy
Guru
Guru


Joined: 14 Feb 2004
Posts: 391
Location: New Plymouth, New Zealand

PostPosted: Thu Sep 21, 2006 10:35 pm    Post subject: Reply with quote

Yeah, would like to hear the answer to this !BUMP! This is one old thread. :P
Back to top
View user's profile Send private message
Zentoo
Apprentice
Apprentice


Joined: 18 Nov 2002
Posts: 194
Location: /dev/console

PostPosted: Wed Oct 04, 2006 3:28 pm    Post subject: Reply with quote

!bump 2!

I'm looking the way to do the same too ! I whish my script could update title for chroot environment to make the difference between chrooted environment and normal one.
_________________
Kernel 4.14.13-ck| Gcc 7.2 | Glibc 2.26
Core i7 6700K @ 4.6GHz | 32Gb
ACCEPT_KEYWORDS="~amd64"
CFLAGS="-march=native -O2 -pipe"
Back to top
View user's profile Send private message
shadeheim
n00b
n00b


Joined: 03 Mar 2007
Posts: 56

PostPosted: Sun Mar 11, 2007 4:13 pm    Post subject: Reply with quote

bump
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum