Search code examples
prompttcshcwd

Replacing part of cwd in prompt with text in TCSH


I am trying to get the following behavior for my prompt in TCSH:

/users/james/ $ cd /projects/android/new_project/1.0/
New Project {1.0} / $ cd vars
New Project {1.0} /vars/ $

I have looked at using cwdcmd but I believe that the variable I assign to store the cwd will only be passed to the prompt once. I've also looked at using set prompt='%c3' etc but this only shows the trailing n dirs, not eliminating the initial ones. Before anyone suggests I change shell I have to use TCSH.

Thanks!


Solution

  • For tcsh I am using following:

    alias precmd 'source ~/bin/prompt.sh'
    

    and inside script I can do whatever I like

    set prompt="┌[%n@%m variable=${ENV_VAR}]\n└[%~] "
    

    This way, your prompt is always up do date. Even more, you can easily create conditional prompt, based on where you are and what variables are set.

    You can find some more "gadgets" here: http://www.owsiak.org/?s=tcsh