I use tcsh. I'd like to have my prompt formatting (coloring/highlighting) change based on the directory I'm in, or other critical aspects of my environment.
I'm not enough of a shell hacker to know how to do this.
Ownership of Current Directory
If I'm in one of "my" directories (i.e., I am owner of the current working directory), then it should have normal appearance. But if I'm in someone else's directory (I do a lot of support and cd
to others' working areas), then I want the prompt to look clearly different.
This is to remind me to not type impolite commands in others' directories. (think make clobber
or p4 sync
, etc.)
Critical Environment Variable Setting
Another important piece of information for my environment is whether a certain environment variable is set, call it SWDEV. If SWDEV is not set, then my scripts and flows come from their default location. But if this variable is set, then it's taken as a new root location for my scripts and flows, with behaviors changing according to the scripts at that location.
It's important to be reminded of the setting of this variable, lest I expect "normal" behavior but instead absentmindedly run code from the new location.
Best Answer
Well, if an external script is an acceptable solution, you could do something like this:
Save that somewhere in your
$PATH
asmake_prompt.pl
and make it executable. And then, in your~/.tcshrc
:This will result in:
You can also add more conditions to change the prompt in specific ways in different directories: