Zsh: Oh My Zsh – customise prompt / PS1


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

and change prompt from

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


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

then source it with:

. ~/.zshrc



I put my custom theme in:





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.



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



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





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


Zsh: horizontal line – hr

add to your .zshrc




Oh My Zsh

Thought I’d give this a go.

From https://ohmyz.sh/

  1. install zsh (on the Mac this is already installed)
  2. set iTerm2 (https://www.iterm2.com/downloads.html) to use this (chsh -s $(which zsh) and in iTerm2 > Preferences > Profiles > Default > General, set the Command to /bin/zsh instead of Login shell. Note – you can also do this via System Preferences: https://stackoverflow.com/a/44547726/343204
  3. Install Oh My Zsh. i.e. sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" –  https://ohmyz.sh/
  4.  If you’re using the agnoster theme, then be aware you’ll need to use Patched fonts (not a big thing but just make sure you install both ASCII and non-ASCII fonts)  – https://github.com/powerline/fonts. i.e. git clone https://github.com/powerline/fonts.git; cd fonts; ./install.sh and select them as the default fonts in iTerm2 > Preferences > Profiles > Text (change both Font and Non-ASCII Font to 12pt Meslo LG S Regular for Powerline)
  5. The most time-consuming stuff was customisation. Copy chosen theme to ~/.oh-my-zsh/custom/themes/agnoster.zsh-theme and customise. i.e. cp ~/.oh-my-zsh/themes/agnoster.zsh-theme ~/.oh-my-zsh/custom/themes/ and set as active in ~/.zshrc (i.e. ZSH_THEME=”agnoster”)
  6. Set aliases and autojump. E.g. I have:

# Aliases
alias c=”clear”
alias l=”ls”
alias sfs=”php bin/console server:run”
alias hr=”printf ‘%*s\n’ \”${COLUMNS:-$(tput cols)}\” ” | tr ‘ ‘ -”
alias h=”history”
alias tf=”terraform”

[[ -s $(brew –prefix)/etc/profile.d/autojump.sh ]] && . $(brew –prefix)/etc/profile.d/autojump.sh


Customisation Notes:


# Dir: current working directory
prompt_dir() {
prompt_segment blue black &quot; <code>basename ${PWD/#$HOME/'~'}</code> &quot;


prompt_segment blue black '%c'


E.g. no user@host in command prompt:



in your zshrc file.



See also



And on the agnoster theme:

  1. red cross means last command had a non-zero exit code: https://github.com/agnoster/agnoster-zsh-theme/issues/54

And a Zsh Cheat Sheet:



My favourite git shortcuts / aliases as:

gst: git status

ga: git add

gcam: git commit -m

gp: git push

gpsup:git push –set-upstream origin $(current_branch)

gd : git diff

gb : git branch

glg: git log –stat –max-count = 10

Full details: https://github.com/robbyrussell/oh-my-zsh/wiki/Cheatsheet