zsh-users
 help / color / mirror / code / Atom feed
* Hi, can someone help me to convert my bash PS1 to zsh?
@ 2022-03-21 16:06 Frank Schwidom
  2022-03-21 16:57 ` Mikael Magnusson
  0 siblings, 1 reply; 10+ messages in thread
From: Frank Schwidom @ 2022-03-21 16:06 UTC (permalink / raw)
  To: zsh-users

And here it is:

(ins)$ echo "$PS1"
\[\]\u@\h \D{%Y-%m-%d %H:%M:%S}:\n\[\]\w\n\[\]\$\[\]

(ins)$ set | grep '^PS1='
PS1=$'\\[\E[32m\\]\\u@\\h \\D{%Y-%m-%d %H:%M:%S}:\\n\\[\E[33m\\]\\w\\n\\[\E[35m\\]\\$\\[\E[0m\\] '

Thanks in advance


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Hi, can someone help me to convert my bash PS1 to zsh?
  2022-03-21 16:06 Hi, can someone help me to convert my bash PS1 to zsh? Frank Schwidom
@ 2022-03-21 16:57 ` Mikael Magnusson
  2022-03-21 17:47   ` Frank Schwidom
  0 siblings, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2022-03-21 16:57 UTC (permalink / raw)
  To: Frank Schwidom; +Cc: zsh-users

On 3/21/22, Frank Schwidom <schwidom@gmx.net> wrote:
> And here it is:
>
> (ins)$ echo "$PS1"
> \[\]\u@\h \D{%Y-%m-%d %H:%M:%S}:\n\[\]\w\n\[\]\$\[\]
>
> (ins)$ set | grep '^PS1='
> PS1=$'\\[\E[32m\\]\\u@\\h \\D{%Y-%m-%d
> %H:%M:%S}:\\n\\[\E[33m\\]\\w\\n\\[\E[35m\\]\\$\\[\E[0m\\] '

The manpage lists all the codes for zsh, which start with %. If you
don't want to scroll down that much, you can also interactively type
PS1=% and then hit tab for an abbreviated list. (the format inside
%D{} is likely to be the exact same)

Separately from that, you'll want to remove any \e[32m stuff and
instead use %F{red} to start a color and %f to end (eg the 0m). If you
use hardcoded escape sequences, you have to write %{ %} around them,
or your cursor will end up in funny places, but there is no reason to
do so for the codes you use.

For example you might have, PS1='%F{blue}%n@%m %D{%Y-%m}%f' etc. (I
don't know what the remaining bash codes correspond to).

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Hi, can someone help me to convert my bash PS1 to zsh?
  2022-03-21 16:57 ` Mikael Magnusson
@ 2022-03-21 17:47   ` Frank Schwidom
  2022-03-21 17:59     ` Mikael Magnusson
                       ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Frank Schwidom @ 2022-03-21 17:47 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Frank Schwidom, zsh-users

On 2022-03-21 17:57:41, Mikael Magnusson wrote:
> On 3/21/22, Frank Schwidom <schwidom@gmx.net> wrote:
> > And here it is:
> >
> > (ins)$ echo "$PS1"
> > \[\]\u@\h \D{%Y-%m-%d %H:%M:%S}:\n\[\]\w\n\[\]\$\[\]
> >
> > (ins)$ set | grep '^PS1='
> > PS1=$'\\[\E[32m\\]\\u@\\h \\D{%Y-%m-%d
> > %H:%M:%S}:\\n\\[\E[33m\\]\\w\\n\\[\E[35m\\]\\$\\[\E[0m\\] '
>
> The manpage lists all the codes for zsh, which start with %. If you
> don't want to scroll down that much, you can also interactively type
> PS1=% and then hit tab for an abbreviated list. (the format inside
> %D{} is likely to be the exact same)
>
> Separately from that, you'll want to remove any \e[32m stuff and
> instead use %F{red} to start a color and %f to end (eg the 0m). If you
> use hardcoded escape sequences, you have to write %{ %} around them,
> or your cursor will end up in funny places, but there is no reason to
> do so for the codes you use.
>
> For example you might have, PS1='%F{blue}%n@%m %D{%Y-%m}%f' etc. (I
> don't know what the remaining bash codes correspond to).
>
> --
> Mikael Magnusson
>

I want to create a multiline prompt. I am missing the code for carriage return or newline.

In bash my Prompt looks like:

user@computer 2022-03-21 18:43:18:
~
(ins)$

This '(ins)' comes from readline in vi mode and tells me in which state I am.

How can I create a newline in PS1?

Regards.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Hi, can someone help me to convert my bash PS1 to zsh?
  2022-03-21 17:47   ` Frank Schwidom
@ 2022-03-21 17:59     ` Mikael Magnusson
  2022-03-21 18:51       ` Roman Perepelitsa
  2022-03-21 18:11     ` Bart Schaefer
  2022-03-21 18:56     ` Lawrence Velázquez
  2 siblings, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2022-03-21 17:59 UTC (permalink / raw)
  To: Frank Schwidom; +Cc: zsh-users

On 3/21/22, Frank Schwidom <schwidom@gmx.net> wrote:
> On 2022-03-21 17:57:41, Mikael Magnusson wrote:
>> On 3/21/22, Frank Schwidom <schwidom@gmx.net> wrote:
>> > And here it is:
>> >
>> > (ins)$ echo "$PS1"
>> > \[\]\u@\h \D{%Y-%m-%d %H:%M:%S}:\n\[\]\w\n\[\]\$\[\]
>> >
>> > (ins)$ set | grep '^PS1='
>> > PS1=$'\\[\E[32m\\]\\u@\\h \\D{%Y-%m-%d
>> > %H:%M:%S}:\\n\\[\E[33m\\]\\w\\n\\[\E[35m\\]\\$\\[\E[0m\\] '
>>
>> The manpage lists all the codes for zsh, which start with %. If you
>> don't want to scroll down that much, you can also interactively type
>> PS1=% and then hit tab for an abbreviated list. (the format inside
>> %D{} is likely to be the exact same)
>>
>> Separately from that, you'll want to remove any \e[32m stuff and
>> instead use %F{red} to start a color and %f to end (eg the 0m). If you
>> use hardcoded escape sequences, you have to write %{ %} around them,
>> or your cursor will end up in funny places, but there is no reason to
>> do so for the codes you use.
>>
>> For example you might have, PS1='%F{blue}%n@%m %D{%Y-%m}%f' etc. (I
>> don't know what the remaining bash codes correspond to).
>>
>> --
>> Mikael Magnusson
>>
>
> I want to create a multiline prompt. I am missing the code for carriage
> return or newline.
>
> In bash my Prompt looks like:
>
> user@computer 2022-03-21 18:43:18:
> ~
> (ins)$
>
> This '(ins)' comes from readline in vi mode and tells me in which state I
> am.
>
> How can I create a newline in PS1?

Just enter a newline, eg
PS1='
'
will give you a prompt with a newline in it.

As for vi mode (I don't use it myself) you probably want to check out
http://bewatermyfriend.org/media/vi-mode.zsh

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Hi, can someone help me to convert my bash PS1 to zsh?
  2022-03-21 17:47   ` Frank Schwidom
  2022-03-21 17:59     ` Mikael Magnusson
@ 2022-03-21 18:11     ` Bart Schaefer
  2022-03-21 18:17       ` Frank Schwidom
  2022-03-21 18:56     ` Lawrence Velázquez
  2 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2022-03-21 18:11 UTC (permalink / raw)
  To: Frank Schwidom; +Cc: Mikael Magnusson, Zsh Users

On Mon, Mar 21, 2022 at 10:59 AM Frank Schwidom <schwidom@gmx.net> wrote:
>
> How can I create a newline in PS1?

Just put an actual newline in it, zsh doesn't have a prompt "escape"
for newline.  This can be accomplished by replacing $'\\n' in your
bash PS1 assignment with $'\n' in zsh.

PS1=$'%F{green}%n@%m %D{%Y-%m-%d %H:%M:%S}:\n%F{yellow}%~\n%F{magenta}%#%f '


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Hi, can someone help me to convert my bash PS1 to zsh?
  2022-03-21 18:11     ` Bart Schaefer
@ 2022-03-21 18:17       ` Frank Schwidom
  0 siblings, 0 replies; 10+ messages in thread
From: Frank Schwidom @ 2022-03-21 18:17 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Frank Schwidom, Mikael Magnusson, Zsh Users

On 2022-03-21 11:11:59, Bart Schaefer wrote:
> On Mon, Mar 21, 2022 at 10:59 AM Frank Schwidom <schwidom@gmx.net> wrote:
> >
> > How can I create a newline in PS1?
>
> Just put an actual newline in it, zsh doesn't have a prompt "escape"
> for newline.  This can be accomplished by replacing $'\\n' in your
> bash PS1 assignment with $'\n' in zsh.
>
> PS1=$'%F{green}%n@%m %D{%Y-%m-%d %H:%M:%S}:\n%F{yellow}%~\n%F{magenta}%#%f '
>

Thanks.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Hi, can someone help me to convert my bash PS1 to zsh?
  2022-03-21 17:59     ` Mikael Magnusson
@ 2022-03-21 18:51       ` Roman Perepelitsa
  2022-03-21 21:43         ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Roman Perepelitsa @ 2022-03-21 18:51 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Frank Schwidom, Zsh Users

On Mon, Mar 21, 2022 at 7:49 PM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> As for vi mode (I don't use it myself) you probably want to check out
> http://bewatermyfriend.org/media/vi-mode.zsh

vi mode is as simple as `bindkey -v`. After that you might want to
define extra bindings but that's not different from defining bindings
for emacs mode.

Roman.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Hi, can someone help me to convert my bash PS1 to zsh?
  2022-03-21 17:47   ` Frank Schwidom
  2022-03-21 17:59     ` Mikael Magnusson
  2022-03-21 18:11     ` Bart Schaefer
@ 2022-03-21 18:56     ` Lawrence Velázquez
  2 siblings, 0 replies; 10+ messages in thread
From: Lawrence Velázquez @ 2022-03-21 18:56 UTC (permalink / raw)
  To: Frank Schwidom; +Cc: zsh-users

On Mon, Mar 21, 2022, at 1:47 PM, Frank Schwidom wrote:
> I want to create a multiline prompt. I am missing the code for carriage 
> return or newline.
>
> In bash my Prompt looks like:
>
> user@computer 2022-03-21 18:43:18:
> ~
> (ins)$
>
> This '(ins)' comes from readline in vi mode and tells me in which state I am.
>
> How can I create a newline in PS1?

Just insert an actual newline.

PS1='single-quoted stuff'$'\n''more single-quoted stuff'

-- 
vq


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Hi, can someone help me to convert my bash PS1 to zsh?
  2022-03-21 18:51       ` Roman Perepelitsa
@ 2022-03-21 21:43         ` Bart Schaefer
  2022-03-22  0:36           ` Frank Schwidom
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2022-03-21 21:43 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Mikael Magnusson, Frank Schwidom, Zsh Users

On Mon, Mar 21, 2022 at 2:14 PM Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> vi mode is as simple as `bindkey -v`.

That doesn't automatically include the (ins) indicator in the prompt,
though, which seemingly the \$ escape in bash does?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Hi, can someone help me to convert my bash PS1 to zsh?
  2022-03-21 21:43         ` Bart Schaefer
@ 2022-03-22  0:36           ` Frank Schwidom
  0 siblings, 0 replies; 10+ messages in thread
From: Frank Schwidom @ 2022-03-22  0:36 UTC (permalink / raw)
  To: Bart Schaefer
  Cc: Roman Perepelitsa, Mikael Magnusson, Frank Schwidom, Zsh Users

On 2022-03-21 14:43:50, Bart Schaefer wrote:
> On Mon, Mar 21, 2022 at 2:14 PM Roman Perepelitsa
> <roman.perepelitsa@gmail.com> wrote:
> >
> > vi mode is as simple as `bindkey -v`.
>
> That doesn't automatically include the (ins) indicator in the prompt,
> though, which seemingly the \$ escape in bash does?
>

No, this is the dollar sign. The (ins) and (cmd) flags are provided by the readline library.

The flag appears on the left side of the last line.
I cannot change it.

I guess zsh don't use readline. But it takes over the settings for the vi keybindings after I startet it from bash. I don't know the exact mechanism.

The readline config at the end of /etc/inputrc is:

set editing-mode vi
set completion-prefix-display-length 1
set show-mode-in-prompt on

The variable 'show-mode-in-prompt' is responsible for this flag.

Regards.



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-03-22  0:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-21 16:06 Hi, can someone help me to convert my bash PS1 to zsh? Frank Schwidom
2022-03-21 16:57 ` Mikael Magnusson
2022-03-21 17:47   ` Frank Schwidom
2022-03-21 17:59     ` Mikael Magnusson
2022-03-21 18:51       ` Roman Perepelitsa
2022-03-21 21:43         ` Bart Schaefer
2022-03-22  0:36           ` Frank Schwidom
2022-03-21 18:11     ` Bart Schaefer
2022-03-21 18:17       ` Frank Schwidom
2022-03-21 18:56     ` Lawrence Velázquez

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).