Date: Thu, 14 Mar 96 8:21:07 MET From: Greg Lehey <lehey.pad@sni.de> To: yvonnes@mediacity.com (Yvonne Shevnin) Cc: questions@freebsd.org Subject: Re: How to make current directory show at the commandline? Message-ID: <199603140724.IAA22491@nixpbe.pdb.sni.de> In-Reply-To: <199603131759.JAA00215@MediaCity.com>; from "Yvonne Shevnin" at Mar 13, 96 9:49 am
next in thread | previous in thread | raw e-mail | index | archive | help
>
> At 08:40 PM 3/13/96 +1030, you wrote:
>> Mike Coffey & Yvonne Shevnin stands accused of saying:
>
> WOW!! You guys definitely get the "A" for thoroughly covering the question
> AND response time. I got 6, count them,6 answers.
> I didn't even submit the question until after 11PM Pacific last nite.
> I even got a response from Australia!
>
> I am going to remember this.
Thanks :-) Let's see if I can get this one to you before midnight
your time.
> Actually, I do have one more question. I am a novice so please bear with me:
>
> I am Telneting into my ISP's server ---
>
> 1) I don't know which shell my ISP uses -- but -- the file in my account is
> .zshrc.
Well, the shell your ISP uses *should* be the one you ask him to use.
As I said before, I prefer bash, but what you have there is obviously
zsh.
> I tried editing this file with: set prompt="`hostname -s`:`pwd`:\! >"
>
> as well as
>
> alias cd 'cd \!*;set prompt="`hostname -s`:`pwd`:\! >"'.
>
> But this didn't work.
No, I don't suppose it would. Both of these commands belong to the
csh family of shells (based on the C shell, csh, including also tcsh
and possibly others). zsh, bash, ksh and sh belong to the Bourne
shell family and have other syntax. I don't think many FreeBSD people
use zsh. Your best bet is the man page. I've browsed in it (do 'man
zshparam' for this particular subject), and got:
PROMPT
The primary prompt string, printed before a command is read;
the default is "%m%# ". If the escape sequence takes an
optional integer, it should appear between the '%' and the
next character of the sequence. The following escape
sequences are recognized:
%% A `%'.
%) A `)'.
%d
%/ Present working directory ($PWD).
%~ $PWD. If it has a named directory as its prefix, that
part is replaced by a ~ followed by the name of the
directory. If it starts with $HOME, that part is
replaced by a ~.
%c
%.
%C Trailing component of $PWD. An integer may follow the
'%' to get more than one component. Unless %C is used,
tilde expansion is performed first.
%h
%! Current history event number
%M The full machine hostname.
%m The hostname up to the first '.'. An integer may
follow the '%' to specify how many components of the
hostname are desired.
%S (%s)
Start (stop) standout mode.
%U (%u)
Start (stop) underline mode.
%B (%b)
Start (stop) boldface mode.
%t
%@ Current time of day, in 12-hour, am/pm format.
%T Current time of day, in 24-hour format.
%* Current time of day in 24-hour format, with seconds.
%n $USERNAME.
%w The date in day-dd format.
%W The date in mm/dd/yy format.
%D The date in yy-mm-dd format.
%D{string}
string is formatted using the strftime function. See
strftime(3) for more details, if your system has it.
%l The line (tty) the user is logged in on.
%? The return code of the last command executed just
before the prompt.
%_ The status of the parser, i.e. the shell constructs
(like `if' and `for') that have been started on the
command line. If given an integer number that many
strings will be printed.
%E Clears to end of line.
%# A '#' if the shell is running as root, a '%' if not.
Equivalent to %(#.#.%%).
%v The value of the first element of the $psvar array
parameter. Following the '%' with an integer gives
that element of the array.
%{...%}
Include a string as a literal escape sequence. The
string within the braces should not change the cursor
position.
%(x.true-text.false-text)
Specifies a ternary expression. The character
following the x is arbitrary; the same character is
used to separate the text for the "true" result from
that for the "false" result. This separator may not
appear in the true-text, except as part of a %
sequence. A `)' may appear in the false-text as `%)'.
True-text and false-text may both contain arbitrarily-
nested escape sequences, including further ternary
expressions. The left parenthesis may be preceded or
followed by a positive integer n, which defaults to
zero. The test character x may be any of the
following:
c
.
~ True if the current path, with prefix replacement,
has at least n elements.
/
C True if the current absolute path has at least n
elements.
t True if the time in minutes is equal to n.
T True if the time in hours is equal to n.
d True if the day of the month is equal to n.
D True if the month is equal to n (January = 0).
w True if the day of the week is equal to n (Sunday
= 0).
? True if the exit status of the last command was n.
# True if the effective uid of the current process
is n.
g True if the effective gid of the current process
is n.
L True if the SHLVL parameter is at least n.
S True if the SECONDS parameter is at least n.
v True if the array psvar has at least n elements.
_ True if at least n shell constructs were started.
%<string<
%>string>
%[xstring]
Specifies truncation behaviour. The third form is
equivalent to `%xstringx', i.e. x may be `<' or `>'.
The numeric argument, which in the third form may
appear immediately after the `[', specifies the maximum
permitted length of the various strings that can be
displayed in the prompt. If this integer is zero, or
missing, truncation is disabled. Truncation is
initially disabled. The forms with `<' truncate at the
left of the string, and the forms with `>' truncate at
the right of the string. For example, if the current
directory is `/home/pike', the prompt `%8<..<%/' will
expand to `..e/pike'. The string will be displayed in
place of the truncated portion of any string. In this
string, the terminating character (`<', `>' or `]'), or
in fact any character, may be quoted by a preceding
`\'. % sequences are not treated specially. If the
string is longer than the specified truncation length,
it will appear in full, completely replacing the
truncated string.
This is quite close to the bash example I gave yesterday. In bash, I
have
PS1="=== \u@\h (`tty`) \w \# -> "
In zsh, this becomes
PS1="=== %n@%m (`tty`) %~ %! -> "
What, you don't see a PS1 in the man page? Neither do I, but zsh
accepts it anyway :-)
> Anyway, I really appreciate everyone's time.
>
> Thanks -- Yvonne.
You're welcome
Greg
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199603140724.IAA22491>
