Operating System - HP-UX
1823415 Members
2570 Online
109655 Solutions
New Discussion юеВ

Configuring the user command shell prompt

 
Andrew Kaplan
Super Advisor

Configuring the user command shell prompt

Hi there --

I am running an 11.11 server and would like to have all user prompts at the command shell appear with the directory that the user is currently in at any given time. My plan is to modify the global-cshrc file and/or the users' individual .cshrc files.

My question is, what is the correct syntax to use to accomplish this? Thanks.
A Journey In The Quest Of Knowledge
8 REPLIES 8
Torsten.
Acclaimed Contributor

Re: Configuring the user command shell prompt

The prompt is stored in variable PS1.

You can search the forum for a lot of solutions or play with it like

export PS1='$PWD >'

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Jonathan Fife
Honored Contributor

Re: Configuring the user command shell prompt

For csh, the prompt variable isn't PS1, it's "prompt". So you'd use:

set prompt = "$cwd:t %"
Decay is inherent in all compounded things. Strive on with diligence
Jeff_Traigle
Honored Contributor

Re: Configuring the user command shell prompt

It's very convoluted for csh. (From eons ago when I was working on SunOS 4.X and IRIX 4.X, I used tcsh and there were some nice shortcuts similar to what bash uses to customize the prompt.)

A Google search yielded the following information from the UNIX FAQ (http://www.faqs.org/faqs/unix-faq/faq/part2/section-4.html).

C Shell (csh):

Put this in your .cshrc - customize the prompt variable the way you want.

alias setprompt 'set prompt="${cwd}% "'
setprompt # to set the initial prompt
alias cd 'chdir \!* && setprompt'

If you use pushd and popd, you'll also need

alias pushd 'pushd \!* && setprompt'
alias popd 'popd \!* && setprompt'

Some C shells don't keep a $cwd variable - you can use `pwd` instead.

If you just want the last component of the current directory in your prompt ("mail% " instead of "/usr/spool/mail% ") you can use

alias setprompt 'set prompt="$cwd:t% "'

Some older csh's get the meaning of && and || reversed. Try doing:

false && echo bug

If it prints "bug", you need to switch && and || (and get a better version of csh.)
--
Jeff Traigle
spex
Honored Contributor

Re: Configuring the user command shell prompt

Hi Andrew,

The syntax for assigning a value to an environmental variable is unique in csh:

% set prompt="[`whoami`@`hostname`]:`pwd` % "

Adding this to the global cshrc should work, unless a user's local .cshrc overrides it.

PCS
Jonathan Fife
Honored Contributor

Re: Configuring the user command shell prompt

Addendum:

$cwd:t gives you just the current directory, but $cwd would give you the full path:

testqa1 1: set prompt = "$cwd:t %"
fifejj %pwd
/home/fifejj
fifejj %set prompt = "$cwd %"
/home/fifejj %



Decay is inherent in all compounded things. Strive on with diligence
Peter Nikitka
Honored Contributor

Re: Configuring the user command shell prompt

Hi,

since I see the string '.cshrc' in your question, I assume C-Shell.
The prompt is stored in the variable
$prompt.

This is the entry in .cshrc:

set HOST=`uname -n`
if ($?prompt && -f ~/.prompt) then
if ("$prompt" != "") source ~/.prompt
alias cd "cd \!*; source ~/.prompt"
endif


This is my ~/.prompt (see attachment for escape-sequences in strings!!) - note that you can drop the CLEARCASE_STUFF if you dont have that Software:

if ( $?prompt ) then
# better set HOST in .cshrc
# set HOST=`hostname`
if ( $?CLEARCASE_ROOT ) then
if ($?tcsh) then
set icon=${CLEARCASE_ROOT:t}
set ccview=%B${icon}%b:
else
set icon=`basename $CLEARCASE_ROOT`
set ccview=${icon}:
endif
else set ccview= icon=$HOST
endif
if ( $AKTPROJEKT != "keinProjekteingestellt" ) then
set ccview=${AKTPROJEKT}:$ccview
endif
if ( ($TERM == xterm) || ($TERM == dtterm) ) then
set prompt=${LOGNAME}@${HOST}:${ccview}"! "
echo -n ""
else
if ($?tcsh) then
set prompt="${HOST}:${ccview}%~:! "
else
set prompt="${HOST}:${ccview}${cwd}:! "
endif
endif
endif


Note that TCSH (Superset of csh) has really nice and usable capabilities, but my prompt takes care of this.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Marvin Strong
Honored Contributor

Re: Configuring the user command shell prompt

well lots of people told you how to do it.

you can man csh for more details.

Also for what its worth, you should not modify individual users .cshrc files. Personally I would be very annoyed if some admin came along and decided what I needed in my .cshrc file. Let the users tend their own .cshrc files.
OldSchool
Honored Contributor

Re: Configuring the user command shell prompt

BTW: I'd stick the code in the /etc/csh.login file (global), as you want it for all users. Just note that an individuals .cshrc could change it