2

I switched from bash shell to zsh. After sourcing a main part of my old .bashrc to .zshrc, I am faced a problem concerning the rendering of prompt with zsh (which works with bash) :

function ps1 {
        # PROMPT SECTION
        BLUE='\[\033[0;34m\]'
        LIGHT_CYAN='\[\033[1;36m\]'
        DEFAULT='\[\033[0m\]'
        PURPLE='\[\033[0;35m\]'
        LIGHT_PURPLE='\[\033[1;35m\]'
        LIGHT_GREEN='\[\033[0;32m\]'
        PINK='\[\033\[0;31m\]'


        # \! - History number of last command
        # $? - Exit value of last command
        # \t - Exit time of last command
        # \w - Current directory (relative)

PS1="$PURPLE|$DEFAULT$LIGHT_GREEN\u@$DEFAULT$LIGHT_CYAN\h$DEFAULT$PURPLE|$DEFAULT\t$PURPLE|$DEFAULT$LIGHT_PURPLE\w$DEFAULT$PURPLE|$DEFAULT "
}

ps1

Here a screen capture of my old bash prompt :

bahs prompt

Now, I would like to have the same prompt but with zsh using exe zsh :

zsh prompt

How to get with zsh the same prompt than with the bash prompt ? Which modifications have I to do ?

UPDATE 1:

I tried the following PS1 for zsh but the rendering is not the expected one :

autoload -U colors && colors
PS1="$fg[purple]|{$fg[green]%u@$fg[cyan]%m$fg[purple]|$fg[purple]%*$fg[purple]|$fg[purple]%~$fg[purple]| "

here's the capture :

trying to get the same zsh prompt than bash

Any idea to the same ?

1

1 Answer 1

0

Here you go:

# %F/%f: start/end Foreground color
# %F{m}/%F{g}/%F{c}: short for %F{magenta}/%F{green}%F{cyan}
# %B/%b: start/end Bold/Bright (depending on your terminal)
# %n: user Name
# %m: Machine name
# %*: 24h time w/ seconds
# %~: pwd, abbreviated
local I='%F{m}|%f'
PS1="$I%B%F{g}%n@%F{c}%m%b$I%*$I%B%F{m}%~%b$I "

This recreates the exact same prompt.

Documentation can be found at http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html

You must log in to answer this question.