Home » Apple

How to Customize Your Terminal Prompt on Mac

Learn the tips and tricks to customize your Mac terminal prompt to create visually captivating and functional terminal interface.

Whether you want to change colors, display helpful information, or experiment with different styles, personalize your Mac today. This guide is filled with techniques, tips, and tricks to help you unleash your creativity and modify Mac Terminal as per your requirements. Get ready to enhance productivity, streamline workflow, and make a statement with a customized Mac zsh terminal prompt.

How to Customize Your Terminal Prompt on Mac

How to Customize Your Terminal Prompt on Mac with zsh command

Are you tired of the plain and monotonous Mac terminal prompt? If yes, it’s time to unleash your creativity and customize it to reflect your unique style. Let’s understand the process of customizing your Mac terminal prompt, providing tips, tricks, and examples to inspire your creativity and elevate your command-line experience.

Quick Answer

To customize the prompt in Terminal using Oh My Zsh on your Mac, you can follow these steps:

1. Launch the Terminal app on your Mac.

2. Enter the command nano ~/.zshrc and press Return to open the .zshrc file in the nano editor.

3. Within the .zshrc profile, locate the PROMPT value and modify it to your preferred prompt format. For example, you can use 

PROMPT=’%n~$’ to change the zsh prompt.

4. Press Ctrl + O to save the changes to the file and press Ctrl + X to exit the nano editor.

Basics of zsh Prompt

Some essential information for instance the last login and the command prompt appears on the screen when you open the terminal window. By default, the prompt is like as given in the image below:

The zsh prompt displays your username and the ~ sign depicts the location of the prompt in the home directory.

terminal window

How to Customize Mac Terminal Prompt?

When customizing the zsh prompt on your Mac, you can modify the information displayed, such as the machine name and username. This information is stored in the zsh shell’s system file located at /etc/zshrc.

The prompt format is defined by the PS1 variable, which uses various symbols to represent different values. Here’s what each variable in the PS1=”%n@%m %1~ %#” format signifies:

  • %n: Represents the username of your account.
  • %m: Represents the model name of your MacBook.
  • %1~: Indicates the current directory path, where the ~ symbol strips the $HOME directory from the display.
  • %#: Displays a # symbol if the shell is running with root privileges, or % if it doesn’t.

To customize the Mac Terminal prompt using Oh My Zsh, follow given steps:

1. Launch the Terminal app on your Mac.

2. Enter the following command and press Return to open the .zshrc file in the nano editor.

nano ~/.zshrc

3. In the .zshrc profile, modify the PROMPT value to reflect your desired prompt format. For example, you can use the following command to customize zsh prompt.

PROMPT='%n~$'

4. Press and hold Ctrl + O to save the changes to the file.

5. Press Ctrl + X to exit the nano editor.

By following these steps, you can easily customize and personalize your zsh prompt in the Terminal app on your Mac.

Also Read: 15 Best Free File Hash Checker Tools

How to Add the Date and Time in the zsh Prompt?

When customizing your zsh prompt, you can conveniently display the present time and date without leaving the Terminal window. Follow these steps to add the time and date to your zsh prompt systematically:

1. Open Terminal and navigate to the zsh configuration file by typing nano ~/.zshrc

2A. To include the date in the yy-mm-dd format, use the %D format specifier.

2B. If you prefer the mm/dd/yy format, use %W.

To append the time to the zsh prompt, use the:

  • %T format specifier for the present time in the 24-hour layout.
  • If you prefer the 12-hour format, use %t.
  • Alternatively, you can use %* to display the time in the 24-hour format, including seconds.

By following these systematic steps, you can effortlessly customize your zsh prompt to include the desired time and date format, enhancing your Terminal experience.

How to Add Colour to Text in the zsh Prompt?

To add colors to the text in the zsh prompt and make your terminal window more lively and colorful, you can follow these steps:

1. Open the Terminal window.

2. Launch the .zshrc profile by running nano ~/.zshrc command.
3. In the .zshrc file, you can customize the text color of the zsh prompt. Choose from a variety of text colors such as green, white, yellow, black, blue, red, magenta, and cyan.

A. For example, to set the prompt text color to cyan, use the following command:

 PROMPT='%F{cyan}%n%f:~$'

B. Additionally, you can use shades of gray to complement the background. For instance, use the following command to set the prompt text color to a shade of gray.

PROMPT='%F{51}%n%f:~$'

Note: Remember that the terminal is compatible with 256 8-bit colors, so you can experiment with different color shades if desired.

By customizing the text color of your zsh prompt in Mac Terminal, you can enhance the visual appeal of your terminal window and make it more engaging to use.

Also Read: How to Open Applications Folder on Mac

How to Add Visual Effects in the zsh Prompt?

In this section, we will discuss how to customize your zsh prompt using formatting options. These options allow you to make your prompt visually appealing and eye-catching. Here’s a systematic breakdown of the steps:

Option I: Bold Text

To make the zsh prompt text bold, you can utilize the PROMPT variable with the following format:

PROMPT='%B%F{51}%n%f%b:~$'
  • %B: Add %B at the beginning of the text to make it bold
  • %F{51}: Set the foreground color to 51 (can be replaced with your desired color code)
  • %n: Insert the username
  • %f: Reset the foreground color
  • %b: Add %b at the end of the text to stop bold formatting

Option II: Highlight Text

To highlight your zsh prompt text, use the following format:

  • %S: Add %S at the beginning of the text to start highlighting
  • %s: Add %s at the end of the text to stop highlighting

Option III: Underline Text

To underline the zsh prompt text, include the following:

  • %U: Add %U at the beginning of the text to start underlining
  • %u: Add %u at the end of the text to stop underlining

By combining these formatting options, you can create a personalized zsh prompt that suits your preferences. Experiment with different color codes and arrangements to find the style that catches your eye.

How to Remove the Last Login Details from zsh Prompt?

In the Terminal app, you can remove the last login time by using the following  command:

touch ~/.hushlogin

Also Read: Fix Cannot be Opened Because the Developer Cannot be Verified in Mac

In conclusion, customizing your Mac terminal prompt goes beyond just improving its appearance. It actually helps make the command-line interface more user-friendly and tailored to your needs. We hope you understood how to customize Mac terminal prompt as well as zsh command. Leave your queries and suggestions in the comments section below, keep exploring our website for more such informative guides.

Leave a Comment

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