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


Click here to return to the 'Why use a script?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Why use a script?
Authored by: a1291762 on May 02, '02 07:39:35PM

> Create a script called chg_dir.sh

Why use a script? Every time you do a 'cd' you have to start a new instance of /bin/sh. Sure it's not a slow thing but it adds just a bit of time to every cd you do.


I would do something like this: (replace <backslash> with a backslash)

alias cd 'chdir <backslash>!*; set prompt="%{<backslash>033]0;[%~]<backslash>007%}[%~]%# "'

chdir is a tcsh build-in that works the same as cd.
<backslash>!* says "put all the arguments to the alias here".
The [%~] part is what goes in the title bar.
Everything after the last } is your normal prompt.
The %# is supposed to change the prompt char to # when you are root. Unfortunately, I don't think it works with "sudo -s".
The default prompt has %u (I think) which puts in your effective username so that would work.

With the above alias, if you type 'cd ~/bin' you'll have a title of '[~/bin]' and a prompt of '[~/bin]> '.



[ Reply to This | # ]
Why use a script? -hostname only?
Authored by: baba on May 02, '02 08:42:35PM

Can this be done so that only the hostname displays in the title?



[ Reply to This | # ]
Re: Why use a script? -hostname only?
Authored by: sjk on May 02, '02 09:30:36PM
Generalized tcsh example:

alias xtitle printf '"\e]2;\!*\a"'

[There are backslashes before the 'e', '!', and 'a' characters in the argument to printf; this avoids using non-printable characters in the alias]

alias cwdcmd xtitle '$cwd'

Replace the argument to xtitle with whatever you want displayed in the Terminal title bar when changing directories in the shell, like:

alias cwdcmd xtitle '`dirs`'

Run:

unalias cwdcmd
xtitle anything

... to set the title bar to something that doesn't change.


[ Reply to This | # ]
Why use a script? -hostname only - success
Authored by: baba on May 03, '02 11:08:22AM

Ah, silly me. I got it to work by specifying machine name:
alias cd 'chdir <backslash>!*; set prompt="%{<backslash>033]0;%m<backslash>007%}[%~]%# "'
so now I have the host in the window and the current path at the prompt.
Most exellent.
The big question now is can I set the terminal background color according to the host??? Right now I keep a bunch of saved term sessions which specify colors for certain hosts. I'd rather it be automatic.



[ Reply to This | # ]