Q: Korn Shell Prompt

Q: Korn Shell Prompt

Post by Robert J. Le » Sat, 14 Jun 1997 04:00:00



Using csh, if I use the following scripts,

Quote:>   alias    cd 'chdir \!* && set prompt="$USER${cwd}# "'
>   if ($?prompt) then
>       set prompt="$USER${cwd}# "
>       set filec
>   endif

I will get an user + directory prompt on every 'cd' command.

Can someone tell me how to do the same thing with Korn shell?

Thanks!

 
 
 

Q: Korn Shell Prompt

Post by Matt Fost » Tue, 17 Jun 1997 04:00:00



: Using csh, if I use the following scripts,

[snip]

: I will get an user + directory prompt on every 'cd' command.

: Can someone tell me how to do the same thing with Korn shell?

Something like


Should do the job.

Matt
--
| Matt Foster | Transactional Systems | DiverseyLever  |
| +44 (0)1 494 468 380 (V) | +44 (0)1 494 468 217 (F)  |
| "We'll give it logons, NTFS, TCPIP, ACLs and call it |
| a multi-user OS."  `No it's not.  It's a GUI.`       |

 
 
 

Q: Korn Shell Prompt

Post by Robert J. Le » Wed, 18 Jun 1997 04:00:00


When I posted the following message, everyone who has responded to me,
seems to be a bit confused. What the following script (embedded in
.cshrc) will do in csh is that whenever you change directory using cd
command, it will display the login user name and the changed directory.
For example, if you are a root and in /bin, you will get a prompt of
"root/bin# '. If you change directory to /usr/src by 'cd /usr/src'
command, your next prompt will become "root/usr/src# '. It's useful
because you always know who you are and where you are.

I only have O's csh manual and am waiting for the O's ksh manual. I need
to reprogram pdksh so that I can add some diagnostics command (It's
critical that this new command will not cause any filesystem access.). I
suppose that the same capability with ksh might be a bit more difficult
because ksh doesn't seem to have an embedded 'chdir' command.

Anyhow, I still appreciate helps from everyone and am still looking
forward to getting a right answer. Hope someone has already done this!

Quote:> Using csh, if I use the following scripts,

> >   alias    cd 'chdir \!* && set prompt="$USER${cwd}# "'

> >   if ($?prompt) then
> >       set prompt="$USER${cwd}# "
> >       set filec
> >   endif

> I will get an user + directory prompt on every 'cd' command.

> Can someone tell me how to do the same thing with Korn shell?

> Thanks!

Bob.
 
 
 

Q: Korn Shell Prompt

Post by Robert J. Le » Wed, 18 Jun 1997 04:00:00


When I posted the following message, everyone who has responded to me,
seems to be a bit confused. What the following script (embedded in
.cshrc) will do in csh is that whenever you change directory using cd
command, it will display the login user name and the changed directory.
For example, if you are a root and in /bin, you will get a prompt of
"root/bin# '. If you change directory to /usr/src by 'cd /usr/src'
command, your next prompt will become "root/usr/src# '. It's useful
because you always know who you are and where you are.

I only have O's csh manual and am waiting for the O's ksh manual. I need

to reprogram pdksh so that I can add some diagnostics command (It's
critical that this new command will not cause any filesystem access.). I

suppose that the same capability with ksh might be a bit more difficult
because ksh doesn't seem to have an embedded 'chdir' command.

Anyhow, I still appreciate helps from everyone and am still looking
forward to getting a right answer. Hope someone has already done this!

Quote:> Using csh, if I use the following scripts,

> >   alias    cd 'chdir \!* && set prompt="$USER${cwd}# "'

> >   if ($?prompt) then
> >       set prompt="$USER${cwd}# "
> >       set filec
> >   endif

> I will get an user + directory prompt on every 'cd' command.

> Can someone tell me how to do the same thing with Korn shell?

> Thanks!

Bob.

p.s. Since this will happen for every cd, I'd like to see the solution
primarily based on the internal commandsof ksh. I still appreciate all
the helps!

 
 
 

Q: Korn Shell Prompt

Post by Chris Andre » Thu, 19 Jun 1997 04:00:00




> : Using csh, if I use the following scripts,

> [snip]

> : I will get an user + directory prompt on every 'cd' command.

> : Can someone tell me how to do the same thing with Korn shell?

> Something like


> Should do the job.

> Matt

much simpler:


SITE=`uname`

Chris

 
 
 

Q: Korn Shell Prompt

Post by J.J. Keijs » Thu, 19 Jun 1997 04:00:00




Quote:>Using csh, if I use the following scripts,

>>   alias    cd 'chdir \!* && set prompt="$USER${cwd}# "'

>>   if ($?prompt) then
>>       set prompt="$USER${cwd}# "
>>       set filec
>>   endif

Very easy. No need for aliasing the CD command with ksh, just use
  export PS1='$LOGNAME $PWD $ '
but mind the single quotes.

HTH,

JJ

----------------------------------------------------------
                 *NOTE*
   My Email return address is not correct
    in order to avoid mass mailings...
     These are the correct addresses
     (but with dashes between all letters):

  Jan Just (JJ) Keijser

  X400: C=NL A=400NET P=SHELL O=SIEP RIJSWIJK
        OU1=EPT-RO OU2=OPENMAIL S=KEIJSER I=JJ
          or

  X400: C=GB A=ATTMAIL P=Logica O=LBV OU1=LBVRTDA S=KEIJSERJJ

  (who said X400 addresses aren't easy to remember :-)

  Just to confuse some of those junkmailers:

 
 
 

Q: Korn Shell Prompt

Post by Jeffrey R. Drum » Thu, 19 Jun 1997 04:00:00


Umm, if you really want it to look that way, how about putting the
following in ~/.profile . . .

PS1='$LOGNAME$PWD$ ';export PS1

--

 - Jeffrey R. Drumm - Systems Integration Specialist
   Maine Medical Center - IS Department
   420 Cumberland Ave - Portland ME 04101
   Voice: 207-871-2150 - FAX: 207-871-6440



Quote:> When I posted the following message, everyone who has responded to me,
> seems to be a bit confused. What the following script (embedded in
> .cshrc) will do in csh is that whenever you change directory using cd
> command, it will display the login user name and the changed directory.
> For example, if you are a root and in /bin, you will get a prompt of
> "root/bin# '. If you change directory to /usr/src by 'cd /usr/src'
> command, your next prompt will become "root/usr/src# '. It's useful
> because you always know who you are and where you are.

<trimmed to keep my newsreader from complaining>
 
 
 

Q: Korn Shell Prompt

Post by Wood » Thu, 19 Jun 1997 04:00:00



> When I posted the following message, everyone who has responded to me,
> seems to be a bit confused. What the following script (embedded in
> .cshrc) will do in csh is that whenever you change directory using cd
> command, it will display the login user name and the changed directory.
> For example, if you are a root and in /bin, you will get a prompt of
> "root/bin# '. If you change directory to /usr/src by 'cd /usr/src'
> command, your next prompt will become "root/usr/src# '. It's useful
> because you always know who you are and where you are.

> I only have O's csh manual and am waiting for the O's ksh manual. I need
> to reprogram pdksh so that I can add some diagnostics command (It's
> critical that this new command will not cause any filesystem access.). I
> suppose that the same capability with ksh might be a bit more difficult
> because ksh doesn't seem to have an embedded 'chdir' command.

> Anyhow, I still appreciate helps from everyone and am still looking
> forward to getting a right answer. Hope someone has already done this!

> > Using csh, if I use the following scripts,

> > >   alias    cd 'chdir \!* && set prompt="$USER${cwd}# "'

> > >   if ($?prompt) then
> > >       set prompt="$USER${cwd}# "
> > >       set filec
> > >   endif

> > I will get an user + directory prompt on every 'cd' command.

> > Can someone tell me how to do the same thing with Korn shell?

> > Thanks!

> Bob.

# located in the ~/.profile

go()
{
        'cd' $1

Quote:}

# supporting alias for "smart" cd
alias cd='go'

# this gives a prompt of

--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ email address altered to avoid SPAMMERS  _/
_/      try kaizen-at-maxinet-dot-com       _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

 
 
 

Q: Korn Shell Prompt

Post by Robert J. Le » Thu, 19 Jun 1997 04:00:00


Thanks!



Bob

 
 
 

Q: Korn Shell Prompt

Post by Matthew Jason Barnha » Fri, 20 Jun 1997 04:00:00



># located in the ~/.profile

>go()
>{
>        'cd' $1

>}

># supporting alias for "smart" cd
>alias cd='go'

># this gives a prompt of


This does the exact same thing (ksh/bash):


matt.

 
 
 

Q: Korn Shell Prompt

Post by Damian J. Anderso » Sat, 21 Jun 1997 04:00:00




> > When I posted the following message, everyone who has responded to me,
> > seems to be a bit confused. What the following script (embedded in
> > .cshrc) will do in csh is that whenever you change directory using cd
> > command, it will display the login user name and the changed directory.
> > For example, if you are a root and in /bin, you will get a prompt of
> > "root/bin# '. If you change directory to /usr/src by 'cd /usr/src'
> > command, your next prompt will become "root/usr/src# '. It's useful
> > because you always know who you are and where you are.

There is a MUCH easier way:

PS1='${PWD}# '

You do not need to execute something every time you change directory.
Try it. :-)

--
Damian J. Anderson      NASA ECS Science Data Engineering
301-925-1023            1616 McCormick Drive

 
 
 

Q: Korn Shell Prompt

Post by Wood » Sat, 21 Jun 1997 04:00:00




> ># located in the ~/.profile

> >go()
> >{
> >        'cd' $1

> >}

> ># supporting alias for "smart" cd
> >alias cd='go'

> ># this gives a prompt of

> This does the exact same thing (ksh/bash):


> matt.

okay... i realize this....

but there are a number of factors involved:

        1) other code (trimmed out) also changes the TITLEBAR of the
           window.

        2) people who use /bin/sh as their login shell get the exact
           same functionality (except they have to use 'go' in place of 'cd')

since i'm working in a mixed sh and ksh environment, i found this works
for me...

YMMV

--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ email address altered to avoid SPAMMERS  _/
_/      try kaizen-at-maxinet-dot-com       _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

 
 
 

Q: Korn Shell Prompt

Post by Tapani Tarvaine » Sun, 22 Jun 1997 04:00:00



Quote:> When I posted the following message, everyone who has responded to me,
> seems to be a bit confused. What the following script (embedded in
> .cshrc) will do in csh is that whenever you change directory using cd
> command, it will display the login user name and the changed directory.
> For example, if you are a root and in /bin, you will get a prompt of
> "root/bin# '. If you change directory to /usr/src by 'cd /usr/src'
> command, your next prompt will become "root/usr/src# '. It's useful
> because you always know who you are and where you are.

Most responses I've seen offered working solutions to exactly that.
Perhaps you should've read them more carefully.  E.g.,

PS1='$LOGNAME$PWD# '

will achieve exactly the effect you describe in ksh: PWD is automatically
updated and the variables are re-evaluated every time the prompt is
displayed.  (Make sure you use single quotes or it won't work.)
Did you try it?  Why isn't it adequate for your needs?

Quote:> I only have O's csh manual and am waiting for the O's ksh manual. I need
> to reprogram pdksh so that I can add some diagnostics command (It's
> critical that this new command will not cause any filesystem access.). I
> suppose that the same capability with ksh might be a bit more difficult
> because ksh doesn't seem to have an embedded 'chdir' command.

What do you mean by "embedded 'chdir'"?  Ksh certainly has built-in 'cd' --
indeed, it's hard to imagine a shell without it.
But if your point was that you want cd to do other things besides
changing the prompt, that's been answered, too: define a function
and alias it to cd:

mycd()
{
  cd $*
  whatever_strange_things_I_want

Quote:}

alias cd=mycd

If you want something to be done whenever the prompt is redisplayed,
whether or not cd was used, use trap DEBUG, possibly again with a function
(as has also been suggested):

trap my_prompter_function DEBUG

If your problem is avoiding file system access, these shouldn't
cause any unless your functions do, besides possibly updating the
history file: that can be avoided by unsetting the HISTFILE variable.

If still can't make it work the way you want, please explain exactly
what you tried, what happened and what you would've wanted to happen.

--
Tapani Tarvainen

 
 
 

Q: Korn Shell Prompt

Post by J.A. Gutierre » Mon, 23 Jun 1997 04:00:00


I found this some time ago at this same ng:

JOSTNAME=`tput bold``hostname -s``tput sgr0`
TILDE='~'

'

sorry but I don't remember the name of the original
poster

Another way

EMOH=`echo $HOME | sed -e 's/\//\\\\\//g'`

_cd()
{
    if [ $# != 0 ]
    then \cd $*
    else \cd
    fi

    export PS1=${JOSTNAME}':'`pwd | sed -e "s/${EMOH}/~/"`'> '

Quote:}

alias cd=_cd

--
J.A. Gutierrez E.                        http://www.cps.unizar.es/~spd/

                                  =                         vu Najefuke
  I never saw the mornin' 'til I stayed up all night    (Tom Waits)