# Cannot figure out how to make csh alias to set xterm title



## skeelol (Nov 3, 2010)

All I want to do is make a simple alias that changes xterm window title to current hostname. Completely easy to do with bash, but I need to do it for csh. 

Anything I try, it just echoes the line back with the hostname, doesn't put it in window title. For example:


```
pingy@pit87% alias mytitle 'echo -n ^[]1\;$HOST\^G'
pingy@pit87% mytitle
^[]1;pit87.pair.com^Gpingy@pit87%
```

It's just not escaping. What am I doing wrong?


----------



## SirDice (Nov 3, 2010)

Here's mine, the tricky bit is the correct escape sequences.


```
switch($TERM)
        case "xterm*":
                setenv TITLE "%{\033]0;%n@%m:%~\007%}"
                breaksw
        default:
                setenv TITLE ""
                breaksw
endsw
```

I've added this to my .cshrc hence the check on TERM. I use it a bit further on to set the prompt:

```
set prompt = "${TITLE}%n@%m:%~%#"
```

This will set the prompt as well as the window's title.


----------



## wblock@ (Nov 3, 2010)

BSD echo(1) doesn't do much.  Use printf(1) instead:

```
% alias mytitle 'printf "\033]0;$HOST\a"'
% mytitle
%
```

For reference, see How to change the title of an xterm.


----------



## skeelol (Nov 3, 2010)

Sweet thanks!


----------

