Thread View: net.unix
8 messages
8 total messages
Started by mike
Wed, 22 Oct 1986 20:46
Korn Shell Question
Author: mike
Date: Wed, 22 Oct 1986 20:46
Date: Wed, 22 Oct 1986 20:46
25 lines
1458 bytes
1458 bytes
I have a Korn Shell question that perhaps someone can answer. I like to
have as my system prompt my current path. When I use csh, I set up my
.cshrc file with these entries:
set prompt = "! `pwd`}" -- this establishes my prompt as my command number
and current path when i first initiate the shell
alias cd 'chdir \!:1; set prompt=\!\`pwd`}\'
this sets up my cd command to not only change
my working directory but to change the prompt.
I would like to have something similar to this in ksh but I'm not sure how
to change PSx on the fly. Has someone done something similar to this??
Any help would be greatly appreciated.
|######################################|
|# J. Michael Flanery #|
|# Computer Science Dept. #|
|# North Texas State University #|
|# UUCP: {ihnp4}!infoswx!ntvax!mike #|
|######################################|
Re: Korn Shell Question
Author: TepperL
Date: Thu, 30 Oct 1986 15:07
Date: Thu, 30 Oct 1986 15:07
26 lines
1499 bytes
1499 bytes
In article <22300001@ntvax>, mike@ntvax.UUCP writes:
>
> I have a Korn Shell question that perhaps someone can answer. I like to
> have as my system prompt my current path. When I use csh, I set up my
> .cshrc file with these entries:
>
> set prompt = "! `pwd`}" -- this establishes my prompt as my command number
> and current path when i first initiate the shell
>
> alias cd 'chdir \!:1; set prompt=\!\`pwd`}\'
> this sets up my cd command to not only change
> my working directory but to change the prompt.
>
> I would like to have something similar to this in ksh but I'm not sure how
> to change PSx on the fly.
In the version of ksh we run here, all you have to do is add to
your .profile:
PS1='$PWD} '
The Korn shell keeps the name of the current directory in the
shell variable PWD. Also, note that you don't need to update
PS1 every time you chdir.
--
Larry Tepper {ihnp4 | allegra}!drutx!druil!lat +1-303-538-1759
Re: Korn Shell Question
Author: carroll
Date: Thu, 30 Oct 1986 16:56
Date: Thu, 30 Oct 1986 16:56
18 lines
1139 bytes
1139 bytes
Ah! Finally a question I know something about. We have tried several
solutions here, and the one that we think works the best is to put into
your .kshrc (remember, to make that work in Kshell, you must have ENV set and
exported to the filename):
ChangeDir=cd
function change_dir
{
$ChangeDir $*
PS1="(!:${PWD}) "
}
alias cd=change_dir
cd .
Using a variable to the cd inside the funtion is needed so that when
the .kshrc is re-executed, you don't get a "recursive function" error. Doing
the cd . changes the prompt to be right immediately after .kshrc executes.
Re: Korn Shell Question
Author: Daniel R. Levy
Date: Thu, 30 Oct 1986 18:41
Date: Thu, 30 Oct 1986 18:41
47 lines
2282 bytes
2282 bytes
In article <22300001@ntvax>, mike@ntvax.UUCP writes:
>
>I have a Korn Shell question that perhaps someone can answer. I like to
>have as my system prompt my current path. When I use csh, I set up my
>.cshrc file with these entries:
>
>set prompt = "! `pwd`}" -- this establishes my prompt as my command number
> and current path when i first initiate the shell
>
>alias cd 'chdir \!:1; set prompt=\!\`pwd`}\'
> this sets up my cd command to not only change
> my working directory but to change the prompt.
>
>I would like to have something similar to this in ksh but I'm not sure how
>to change PSx on the fly. Has someone done something similar to this??
>
>Any help would be greatly appreciated.
>
>
>
> |######################################|
> |# J. Michael Flanery #|
> |# Computer Science Dept. #|
> |# North Texas State University #|
> |# UUCP: {ihnp4}!infoswx!ntvax!mike #|
> |######################################|
In ksh, define (say) chdir as a shell function, then alias cd to it.
ksh aliases aren't recursive, so this works:
case $0 in
*ksh) PS1=!$PWD}
chdir()
{
cd $1 # this shell function will return here if the cd fails
PS1=!$PWD\}
}
alias cd=chdir
esac
--
------------------------------- Disclaimer: The views contained herein are
| dan levy | yvel nad | my own and are not at all those of my em-
| an engihacker @ | ployer or the administrator of any computer
| at&t computer systems division | upon which I may hack.
| skokie, illinois |
-------------------------------- Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
go for it! allegra,ulysses,vax135}!ttrdc!levy
Re: Korn Shell Question
Author: price
Date: Fri, 31 Oct 1986 03:56
Date: Fri, 31 Oct 1986 03:56
3 lines
642 bytes
642 bytes
Ok, now, is it possible to chage PS1 on the fly when you're using the Bourne shell?
Re: Korn Shell Question
Author: jona
Date: Fri, 31 Oct 1986 13:20
Date: Fri, 31 Oct 1986 13:20
14 lines
1102 bytes
1102 bytes
In ksh this is really a simple thing to do and you can extend in to be even
more useful by using this:
PS1="\${PWD#\$HOME/}> "
What this does is remove your home directory name from the beginning of
the prompt if you are anywhere below your home directory.
This is really useful because when you are in your own
directory structure your prompt isn't quite as long - and since my home
directory is 14 characters long (including /'s) it is nice.
Example: my home directory is '/m/swdev/jona' so if I am in /m/swdev/jona/bin
my prompt will be 'bin> ' instead of 'm/swdev/jona/bin> '.
Re: Korn Shell Question
Author: carroll
Date: Fri, 31 Oct 1986 17:58
Date: Fri, 31 Oct 1986 17:58
8 lines
1048 bytes
1048 bytes
Well, that does seem to work. I remember it failing for csh, but I guess that's because you have to use `pwd` instead of a variable. For the bourne shell, you can do the same thing, except in your .profile instead of .kshrc, and use change_dir() instead of function change_dir. Unfortunately, that means that it won't work for any forked shells (such as out of notesfiles or whatever). Also, you have to use `pwd` because I don't think that Bourne shell supports the var PWD.
Re: Korn Shell Question
Author: Adam V. Reed
Date: Sun, 02 Nov 1986 04:27
Date: Sun, 02 Nov 1986 04:27
21 lines
1441 bytes
1441 bytes
> I have a Korn Shell question that perhaps someone can answer. I like to > have as my system prompt my current path. When I use csh, I set up my > .cshrc file with these entries: > > set prompt = "! `pwd`}" -- this establishes my prompt as my command number > and current path when i first initiate the shell > > alias cd 'chdir \!:1; set prompt=\!\`pwd`}\' > this sets up my cd command to not only change > my working directory but to change the prompt. > > I would like to have something similar to this in ksh but I'm not sure how > to change PSx on the fly. Has someone done something similar to this?? > > |# J. Michael Flanery #| Ksh maintains the path of the working directory in $PWD, so you can use PS1='! $PWD $ ' which gives you the history file line number, the path of the working directory, and "$ " to remind you you're using ksh. Adam Reed (ihnp4!mtund!adam||attmail!adamreed)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads