Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'An simpler alternative for bash' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An simpler alternative for bash
Authored by: melquiades on May 23, '01 11:41:48PM
If you're using bash, you can just include the title-changing code in your prompt (I put this line in my .profile): PS1="\[^[]2;custom-window-title^G\]custom-prompt" For example, I use the following: PS1="\[^[]2;\u@\H (\W)^G\]\h (\W)\\$ " There are a bunch of codes you can use in your prompt (copied from the bash man page): d the date in "Weekday Month Date" format h the hostname up to the first `.' H the hostname j the number of jobs currently managed by the shell l the basename of the shell's terminal device name n newline r carriage return s the name of the shell, the basename of $0 (the portion following the final slash) t the current time in 24-hour HH:MM:SS format T the current time in 12-hour HH:MM:SS format @ the current time in 12-hour am/pm format u the username of the current user v the version of bash (e.g., 2.00) V the release of bash, version + patchlevel (e.g., 2.00.0) w the current working directory W the basename of the current working direc- tory ! the history number of this command # the command number of this command $ if the effective UID is 0, a #, otherwise a $ nnn the character corresponding to the octal number nnn a backslash I'm sure there's an analogous way for tcsh.

[ Reply to This | # ]
An simpler alternative for tcsh
Authored by: leo on May 24, '01 04:54:08PM

In tcsh you do not need to modify the prompt in order to change the window title.
You may use an alias called cwdcmd. tcsh will execute this alias whenever the cd
command is executed. Here are two aliases to accomplish this task.

alias settitle 'echo -n "^[]2;"!*"^G"'
alias cwdcmd 'settitle $cwd'

I personally use the following command, which will do an ls and change
the window title everytime I move to a new directory.

alias cwdcmd 'ls ; settitle $cwd'

and here is an example to modify the prompt using an environment variable.
Now your promt will always contain the login name and the trailing component
of $cwd.

set prompt="$USER[%c]: "

You may get the above mentioned commands by downloading files aliases.mine and
environment.mine from my shared folder (copy them to ~/Library/init/tcsh).

[ Reply to This | # ]