No Next Item No Next Conference Can't Favor Can't Forget Item List Conference Home Entrance    Help
View Responses


Grex Info Item 245: customizing your prompt
Entered by brenda on Thu May 18 06:40:24 UTC 1995:

I know i've seen this somewhere, but I can't find it.

Is there a way to make my prompt show what dir I'm in?

for example, if i'm in my own subdir dikued, I'd like my
prompt to show:
        ./dikued:
or if i'm in look., it would say:
        ./look.:

And so on.  Is this possible?

16 responses total.



#1 of 16 by davel on Thu May 18 10:36:57 1995:

The answer depends heavily on what shell you use.  As far as I know, it's
impossible in sh.  In bash (an enhanced sh, which I'm currently using
myself) I use:
        PS1='${PWD}$ '
        export PS1
I see you use csh, Brenda, & I'm afraid I can't remember how you should
do it.  (I remember that it's supposed to be something fairly cumbersome,
and that tcsh (an enhanced csh) makes it much easier.)  So maybe remmers
or Valerie or someone will jump in for the csh side of things.


#2 of 16 by remmers on Thu May 18 11:42:30 1995:

It's been a while since I used csh, so I may get some of the fine
points wrong, but the basic idea is that in your .cshrc file, you
alias 'cd' to something that sets the prompt as well as changing
directory, i.e. something like this:

        alias cd 'chdir \@
        alias cd 'chdir \!*; set prompt="$CWD <other stuff>"'

The C shell variable CWD always contains the current working directory.

Like Dave says, it's cumbersome.  I'd recommend changing shells to
tcsh.  It's upward compatible with csh, so your .login and .cshrc files
should continue to work.  In addition, including the current directory
in your prompt string is very simple; just include the string  %/  in
your prompt definition.  Have a look at /u/remmers/.login to see an
example.


#3 of 16 by robh on Thu May 18 22:53:46 1995:

Are there any disadvantages to switching to tcsh?
Will csh scripts work with tcsh?


#4 of 16 by scg on Fri May 19 00:03:02 1995:

Csh scripts should start with "#!/bin/csh", in which case, tcsh should
still run them in csh.  I can't see why there would be a problem.


#5 of 16 by davel on Fri May 19 00:14:33 1995:

Hmm.  John, doesn't it have to be $cwd instead of $CWD?  (And I presume that
the first line you gave wasn't supposed to be there, right?)  Brenda, it
looks like that basically works, though, with $cwd instead of $CWD (when
I just tried it).

Rob, in theory (& *most* of the time in practice) csh scripts should run
in tcsh (& same comments in all this for sh->bash).  The enhanced version
is designed to be compatible, & someone worked really hard to make it so.
The problem, of course, is in the existence of enhancements, which are by
their nature incompatibilities.  For example, there are some builtin
predefined variables that aren't in csh; if your script happens to rely
on the possibility of their being undefined until you set them, watch out.
But in general, if it's legal in a csh script, it should work the same way.
(I'm operating slightly out of my depth, & anyone who knows better should
feel free to correct me if I'm wrong - but I don't think I am.  Those more
familiar with csh & tcsh certainly may want to provide examples.)

The other thing to worry about, of course, is: if I get very used to using
tcsh, what am I going to do if I find myself on some benighted system that
only supports csh?  I don't have much of a feel for how universally
available tcsh is; I know it's not on the (SYSV-ish) systems I'm most
familiar with.  (But the easier command history it provides *is* available
with an addon to sh & csh on those systems.)


#6 of 16 by davel on Fri May 19 00:16:34 1995:

Um, Steve slipped in with an essential point I'd forgotten for the moment.
There is always that.


#7 of 16 by popcorn on Wed May 24 12:19:44 1995:

This response has been erased.



#8 of 16 by remmers on Wed May 24 13:51:43 1995:

I use tcsh and control-w works for me.


#9 of 16 by popcorn on Wed May 24 16:51:41 1995:

This response has been erased.



#10 of 16 by dam on Thu May 25 02:22:06 1995:

I've got "bind emacs" somewhere in my .login, to change the way the
tcsh interface handles keystrokes.  I just checked again, and it's true
for me that ^W deletes the entire line, ESC-BS deletes the word to the
left, and ^X-BS makes a cute beep, probably because ^X typically starts
the emacs extended command mode.
 
whatever the default key binding was for tcsh was really bugging me,
the command history and cursor keys and inserts/overstrikes were not
working the way I was expecting to or could get used to.


#11 of 16 by curby on Thu May 25 05:49:31 1995:

I think that vi style keys are the default for tcsh.  I agree that
emacs style keys are much better.  Even though, for religious reasons,
I cannot support emacs for anything else...  <grin>


#12 of 16 by remmers on Thu May 25 09:57:48 1995:

Hmmm... I use tcsh on a couple of other systems besides Grex.  On those
I get the emacs key bindings by default; here I get vi.  Perhaps the
default is a compile-time or configuration option.  Does tcsh have a
global config file?


#13 of 16 by dam on Fri May 26 12:42:36 1995:

ya know, (re#12) I noticed that, too.  Long ago when I had an account
on mudos and was first introduced to tcsh, the keys were emacs-style.
When tcsh first came here, I was happy to switch over.  It only took
a few hours to get through the manual to find out that there were
different key-interface flavours, and only a few more to get them
switched...


#14 of 16 by curby on Fri May 26 15:58:17 1995:

I think that you can change the default key bindings when compiling, ir
in your config files.  I am not sure about a global config file...




#15 of 16 by kentn on Sat May 27 20:16:11 1995:

If you compile tcsh with the author's makefile and other configs, you
get emacs key bindings.  tcsh has a lot of options you can set before
you compile; one of them is the default command line edit key
bindings.

Check "config_f.h" for the feature settings.  If the following is
undef'd you get emacs bindings:

/*
 * VIDEFAULT    Make the VI mode editor the default 
*/ 
#define VIDEFAULT

Seems to me that "bindkey -v" will also set all your command line edit
keys to vi-style.  ("bind" is an old command that has been repaced by
"bindkey" in the newer versions of tcsh; the latest version is 6.06,
I think).



#16 of 16 by popcorn on Mon May 29 11:23:09 1995:

This response has been erased.

Response not possible - You must register and login before posting.

No Next Item No Next Conference Can't Favor Can't Forget Item List Conference Home Entrance    Help

- Backtalk version 1.3.30 - Copyright 1996-2006, Jan Wolter and Steve Weiss