Adding Your Hostname to the ZSH Prompt (with oh-my-zsh)

Adding your server hostname to the ZSH prompt (with oh-my-zsh installed) is super helpful if you work with multiple SSH sessions. Follow the steps below to get started!

Assuming oh-my-zsh is installed, navigate to your themes directory. This is typically in your home systems folder:

cd ~/.oh-my.zsh/themes

Duplicate the default robbyrussell.zsh-theme theme to create your own custom theme:

cp robbyrussell.zsh-theme mytheme.zsh-theme

Modify the new theme mytheme.zsh-theme with your desired prompt. Here’s what mine looks like:

PROMPT='%{$fg_bold[white]%}%M %{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'

This will add the hostname (in bold white) before the leading right-arrow. The important part here is %{$fg_bold[white]%}%M.

Save the file with your new changes, and then change your default ZSH theme in the ~/.zshrcfile. You will notice a parameter called “ZSH_THEME” which is where you will update your ZSH theme:


All you need to do now is reload your ZSH shell, this can be done by running the command below:

source ~/.zshrc

Your prompt should now resemble the following:

hostname.local ➜  ~

One thought on “Adding Your Hostname to the ZSH Prompt (with oh-my-zsh)

  1. Or just add this line in your .zshrc :
    export PROMPT=’%(!.%{%F{yellow}%}.)$USER@%{$fg[white]%}%M ${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)’


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s