user1069609
user1069609

Reputation: 871

How to translate small bash code to csh / tcsh (setting GNOME terminal title)

I need help to translate the following bash code to tcsh :

case $TERM in
    (xterm*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}\007"'
    ;;
esac

It is part of my .bashrc on all the machines which have bash as login shell. The code sets the GNOME terminal title to user@somehost (obviously with the real user name and host name). However some hosts have tcsh as login shell, so I need to translate the code into tcsh and add it to the .tcshrc .

I considered to somehow source another file with the bash code from inside the .tcshrc file, but I couldn't make it work.

Upvotes: 1

Views: 1962

Answers (1)

Dennis Williamson
Dennis Williamson

Reputation: 360085

You can either add the sequence to your prompt string or use precmd.

set prompt = "%{\033]0;%n@%M\007%}$prompt"

or

alias precmd 'echo -n "\033]0;$user@`hostname`\007"'

The conditional assignment:

switch ($term)
    case xterm*:
        set prompt = "%{\033]0;%n@%M\007%}$prompt"  # or the alias command
    breaksw
endsw

Upvotes: 1

Related Questions