Current directory in the ksh prompt?

Current directory in the ksh prompt?

Post by Marc Unang » Mon, 29 Apr 1991 09:27:03



I realize this is probably a FAQ, but I can't seem to find the FAQ
list on this machine or any of the NNTP servers around here (if you
know of an NNTP server that accepts connections from anybody and keeps
news a long time, like for over two weeks, please let me know!), so
I'll ask away...

I recently started using ksh, and one thing I miss dearly from csh is
the ability to put the current directory in your prompt.  With csh, it
can be done by aliasing the cd command to something that does the cd
and then re-sets your prompt, using `pwd` to get the new directory.
Unfortunately, it seems that you can't use the parameters inside an
alias like you can in csh, so this trick doesn't work.  Is there a
different trick for ksh, or am I just going to have to live with
typing "pwd" all the time?

--
Marc Unangst               |

...!hela!mudos!mju         |

 
 
 

Current directory in the ksh prompt?

Post by Michael Stefan » Mon, 29 Apr 1991 18:39:31



Quote:>I recently started using ksh, and one thing I miss dearly from csh is
>the ability to put the current directory in your prompt. [...]

My personal favorite is this one (it prints out the basename of the
current directory):

PS1='${PWD##*/}> '

If you want the whole thing, then just use some variation of:

PS1='${PWD}> '

--
Michael Stefanik, MGI Inc, Los Angeles | Opinions stated are never realistic
Title of the week: Systems Engineer    | UUCP: ...!uunet!bria!mike
-------------------------------------------------------------------------------
If MS-DOS didn't exist, who would UNIX programmers have to make fun of?

 
 
 

Current directory in the ksh prompt?

Post by Rob Log » Tue, 30 Apr 1991 08:47:27



>I realize this is probably a FAQ, but I can't seem to find the FAQ
>list on this machine or any of the NNTP servers around here (if you
>know of an NNTP server that accepts connections from anybody and keeps
>news a long time, like for over two weeks, please let me know!), so
>I'll ask away...
>I recently started using ksh, and one thing I miss dearly from csh is
>the ability to put the current directory in your prompt.  With csh, it
>can be done by aliasing the cd command to something that does the cd
>and then re-sets your prompt, using `pwd` to get the new directory.
>Unfortunately, it seems that you can't use the parameters inside an
>alias like you can in csh, so this trick doesn't work.  Is there a
>different trick for ksh, or am I just going to have to live with
>typing "pwd" all the time?
>--
>Marc Unangst               |

>...!hela!mudos!mju         |

Try


You will have to customise the id and hostname commands to what ever you
machine uses to return current user id and hostname.

--

Telecom Australia                            FAX:   +61 7 837 4704
TNE Computer Support Services                PH:    +61 7 837 5174
Brisbane Office                              "These are my opinions alone"

 
 
 

Current directory in the ksh prompt?

Post by Marc Unang » Mon, 29 Apr 1991 13:01:43



> I recently started using ksh, and one thing I miss dearly from csh is
> the ability to put the current directory in your prompt.  With csh, it

[...]

Well, I've gotten many replies to this question.  The general idea is
to create a function called "_cd" (or something similar), which does
the actual cd and then resets the prompt, and then alias cd to this
function.  The slickest answer was by Mike O'Connor, who submitted the
following function:

function _cd {
        unalias cd
        cd $1
        alias cd=_cd
        if [ "${PWD#${HOME}}" != "${PWD}" ]
        then

        else

        fi

Quote:}

This cleverly uses the ksh string-substitution features to strip the
trailing domain name off $HOSTNAME, as well as substitute "~/" for the
leading path when the current directory is in or below your home
directory.  The "unalias cd; cd $1; alias cd=_cd" part could be
replaced with "\cd $1", I believe; otherwise, this answer is almost
perfect.

Thanks to everybody who replied to this!

--
Marc Unangst               |

...!hela!mudos!mju         |

 
 
 

Current directory in the ksh prompt?

Post by Odin Anders » Wed, 01 May 1991 11:14:29




>> I recently started using ksh, and one thing I miss dearly from csh is
>> the ability to put the current directory in your prompt.  With csh, it
>[...]

>Well, I've gotten many replies to this question.  The general idea is
>to create a function called "_cd" (or something similar), which does
>the actual cd and then resets the prompt, and then alias cd to this
>function.

Isn't the folowing more simple while still doing what you want:
         PS1=" \$PWD> "
This works well for me (I like the whole path).  

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Sincerely,       + Programing is like _______, it must be _______ to be good.+
+     __             + What is the most stable 3-dimensional shape?            +
+    /  ) __/ . __     + How many bytes are in a mouthfull?                    +
+   (__/ (_<_<_/ <_      + Never, Never, Say never...                          +
+                          + Always carry a fingernail clipper!                +

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 
 
 

Current directory in the ksh prompt?

Post by Mike Mil » Thu, 02 May 1991 01:17:42




>> I recently started using ksh, and one thing I miss dearly from csh is
>> the ability to put the current directory in your prompt.  With csh, it
>[...]

Rather than a function, you can just do this:

PS1='${PWD##*/}<!>$ '

...this gives you the PWD with current history #, and a $ prompt...

--


--(606) 255-3583, 257-3092
    "Drawing on my fine command of language, I said nothing." -- Mark Twain

 
 
 

Current directory in the ksh prompt?

Post by Donn Ped » Wed, 01 May 1991 23:20:49



> Isn't the folowing more simple while still doing what you want:
>     PS1=" \$PWD> "
> This works well for me (I like the whole path).  

If you only want the last component of the path:

        PS1='${PWD##*/} > '

Note that this is running under ksh.


 
 
 

Current directory in the ksh prompt?

Post by Alex Martel » Mon, 06 May 1991 09:24:35


        ...
:directory.  The "unalias cd; cd $1; alias cd=_cd" part could be
:replaced with "\cd $1", I believe; otherwise, this answer is almost
:perfect.

One little tidbit to push it 0.0001 nearer to perfection: change that
$1 to $*, so you don't lose the ksh feature to say, e.g., 'cd lib spool'
to change from /usr/lib/uucp to /usr/spool/uucp...
--
Alex Martelli - (home snailmail:) v. Barontini 27, 40138 Bologna, ITALIA

Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434;
Fax: ++39 (51) 366964 (work only), Fidonet: 332/401.3 (home only).

 
 
 

1. ksh: current directory in prompt

I've spent too much time trying to my korn shell prompt (PS1) to show
the current directory...  Help would be appreciated.  Thanks.

--------------------------------------------------------------------------
Laurie Kramer                           Genome Data Base

http://gdbdoc.gdb.org/~laurie/          http://gdbwww.gdb.org/
--------------------------------------------------------------------------
        "Nobody gets me. I'm the wind, baby." - Tom Servo
--------------------------------------------------------------------------

2. Help! 3DImage 9750 doesn't work with X

3. Changing prompt to reflect new current working directory in ksh

4. getlogin() problem

5. Current directory display with ksh prompt

6. Reporting tools

7. current dir in ksh prompt

8. WTB: Red Hat Linux 5.2/Alpha

9. ksh newbie requires prompt to show current working dir

10. Q:Current time as part of ksh prompt?

11. how do I set the ksh prompt so it shows the current time?

12. Current time in the ksh prompt?

13. Current directory in prompt in Korn shell?