* New-line in prompt
@ 1998-11-09 13:27 Owen M. Astley
1998-11-09 15:19 ` Phil Pennock
1998-11-09 20:30 ` Bart Schaefer
0 siblings, 2 replies; 3+ messages in thread
From: Owen M. Astley @ 1998-11-09 13:27 UTC (permalink / raw)
To: zsh-users
I am trying to get a new line (\n) in a prompt (actually I only want the
new line if the current one is too long). Has anybody got any idea about
how to do this? %{\n%} works but, as the man page says, it shouldn't
change the cursor position (for obvious reasons if you use it).
Thanks, Owen
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: New-line in prompt
1998-11-09 13:27 New-line in prompt Owen M. Astley
@ 1998-11-09 15:19 ` Phil Pennock
1998-11-09 20:30 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: Phil Pennock @ 1998-11-09 15:19 UTC (permalink / raw)
To: oma1000; +Cc: zsh-users
Typing away merrily, Owen M. Astley produced the immortal words:
> I am trying to get a new line (\n) in a prompt (actually I only want the
> new line if the current one is too long). Has anybody got any idea about
> how to do this? %{\n%} works but, as the man page says, it shouldn't
> change the cursor position (for obvious reasons if you use it).
How about using a print in the precmd special function?
If you want the normal prompt escapes in it, use the -P option to print.
precmd is called before every prompt.
% function precmd { print -P Funky-%~ }
Funky-~
% echo
Funky-~
% cd /usr
Funky-/usr
%
Hope this helps.
--
--> Phil Pennock ; GAT d- s+:+ a22 C++(++++) UL++++/I+++/S+++/H+ P++@ L+++
E-@ W(+) N>++ o !K w--- O>+ M V !PS PE Y+ PGP+ t-- 5++ X+ R !tv b++>+++ DI+ D+
G+ e+ h* r y?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: New-line in prompt
1998-11-09 13:27 New-line in prompt Owen M. Astley
1998-11-09 15:19 ` Phil Pennock
@ 1998-11-09 20:30 ` Bart Schaefer
1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1998-11-09 20:30 UTC (permalink / raw)
To: zsh-users
On Nov 9, 1:27pm, Owen M. Astley wrote:
} Subject: New-line in prompt
}
} I am trying to get a new line (\n) in a prompt (actually I only want the
} new line if the current one is too long). Has anybody got any idea about
} how to do this? %{\n%} works but, as the man page says, it shouldn't
} change the cursor position (for obvious reasons if you use it).
This has spawned a discussion on zsh-workers that I thought I'd let the
zsh-users know about.
(1) Putting a newline in the prompt is a FAQ; the short answer is, you
just quote it:
PS1='stuff before the newline
stuff after the newline'
(2) A patch for 3.1.5 has been posted to add a "line length" test to the
conditional prompt syntax. Without that patch, there's no simple way to
accomplish "insert Y if the prompt so far is longer than X characters."
Here's a not-so-simple way, but note that it fails if you have an non-
printing characters in the prompt (escapes for bold and underline, or
anything in %{...%}, etc.).
precmd() {
# ... whatever you now have in precmd, followed by:
fold-prompt
}
# Don't set PROMPT or PS1, instead set this array:
parts_of_PS1=(%m %n "%~" "%#") # For example
fold-prompt() {
emulate -R zsh
setopt localoptions
local tmp_PS1="" p P
local fold_at=$[$COLUMNS-1] # Adjust to taste
for p in $parts_of_PS1
do
P=$(print -nP $p)
if [[ $[$#tmp_PS1+$#P] -lt $fold_at ]]
then
tmp_PS1="${tmp_PS1:+$tmp_PS1 }$P"
else
((fold_at += $#tmp_PS1 + 1))
tmp_PS1="$tmp_PS1
$P" # Note, newline enclosed in quotes ending on this line
fi
done
PS1="${tmp_PS1:gs/%/%%/} "
}
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1998-11-09 20:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-09 13:27 New-line in prompt Owen M. Astley
1998-11-09 15:19 ` Phil Pennock
1998-11-09 20:30 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).