• Reset your password
Home
OO PHP, Drupal, Symfony Developer and Architect
Tim Rabbetts

Main navigation

  • Home
  • Blog
  • Log in

Customize Zsh Prompt Hostname Colors for Multiple Servers

Breadcrumb

  • Home
  • blog
  • customize zsh prompt hostname colors for multiple servers
  • Customize Zsh Prompt Hostname Colors for Multiple Servers
Tim
Rabbetts
By zarexogre | Sat, 11/11/2023
zsh color host
zsh

I aimed to enhance the visual appeal of my Linux command line prompt when connecting to different servers via SSH. My Linux system is equipped with Zsh, and I've installed Oh My Zsh. To achieve this, I made some customizations to the "agnoster.zsh-theme" file located at "~/.oh-my-zsh/themes/agnoster.zsh-theme." Inside this file, I made modifications around line 90, specifically within the "prompt_context" function, which is responsible for rendering the hostname. I updated the function to use two color variables, which I subsequently defined in my ".zshrc" configuration file. Here's the modified code:

 

In the "agnoster.zsh-theme" file:

prompt_context() {
 if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
   prompt_segment $PBG $PFG "%(!.%{%F{yellow}%}.)%n@%m"
 fi
}

In my ".zshrc" configuration file, I added the following two lines to define the color variables:

# Define custom prompt colors
export PBG="black"
export PFG="default"
 

These changes have effectively improved the appearance of my command line prompt, making it more visually appealing when I SSH into different servers.

zsh color host