Zsh: Oh My Zsh – customise prompt / PS1

TLDR

vim +92 ~/.oh-my-zsh/custom/themes/agnoster.zsh-theme

and change prompt from

prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"

to

prompt_segment black default "%(!.%{%F{yellow}%}.)text-you-want-to-appear"

then source it with:

. ~/.zshrc

 

DETAILS

I put my custom theme in:

~/.oh-my-zsh/custom/themes/

e.g.

~/.oh-my-zsh/custom/themes/agnoster.zsh-theme

 

Editing the PS1 means changing the PROMPTvariable which looks like this:

PROMPT='%{%f%b%k%}$(build_prompt) '

 

From man zshmisc

%{…%}
Include a string as a literal escape sequence. The string within the braces
should not change the cursor position. Brace pairs can nest.

A positive numeric argument between the % and the { is treated as described for
%G below.

And

%f%b%k

%F (%f)
Start (stop) using a different foreground colour, if supported by the terminal.
The colour may be specified two ways: either as a numeric argument, as normal,
or by a sequence in braces following the %F, for example %F{red}. In the lat-
ter case the values allowed are as described for the fg zle_highlight
attribute; see Character Highlighting in zshzle(1). This means that numeric
colours are allowed in the second format also.

%B (%b)
Start (stop) boldface mode

%K (%k)
Start (stop) using a different bacKground colour. The syntax is identical to
that for %F and %f.

 

and

I wanted to remove my username which would point to this:

and

%n@%m

is

%n $USERNAME.

%m The hostname up to the first .'. An integer may follow the %’ to specify how
many components of the hostname are desired. With a negative integer, trailing
components of the hostname are shown.

https://stackoverflow.com/questions/35281630/how-do-i-change-my-ps1-on-a-macbook-for-oh-my-zsh

Leave a Reply

Your email address will not be published. Required fields are marked *