Changing the prompt in the terminal is a quick way to personalize your workspace, making it easier to read and distinguish from the default appearance. The zsh shell, which became the default shell in macOS Catalina and later, allows for a highly customizable prompt using themes and plugins.
The zsh prompt, also known as the PS1 (Prompt String 1), is what you see at the beginning of each line in your terminal. By default, it displays the name of the user, the name of the machine, and the current directory. Customizing it can provide quick access to more information, reduce clutter, or simply add some fun visual aesthetics to your terminal sessions.
On macOS, the zsh configuration file is stored at ~/.zshrc, which is where you'd make changes to personalize the prompt. Before customizing, it's a good idea to backup this file.
% echo $PROMPT %n@%m %1~ %#
% export PROMPT="[%*] %n@%m$ " [9:39:40] shakir@host$
Character | Explanation |
---|---|
%n | Username |
%m | Hostname (up to the first dot) |
%M | Full hostname |
%~ | Current working directory |
%# | Root indicator (#for root, $for a regular user) |
%% | A literal % |
%D | Current date |
%T | Current time |
%t | Current time in 24-hour format |
%* | Current time in 12-hour format |
%d | Current directory path |
%c | The trailing component of the current directory |
%1~ | Truncate directory to the last 1 part |
%2~ | Truncate directory to the last 2 parts |
%3~ | Truncate directory to the last 3 parts |
%L | The current shell level |
%j | The number of jobs managed by the shell |
$ echo 'export PROMPT="[%*] %n@%m$ "' >> ~/.zshrc
Manually edit the PROMPT declaration in ~/.zshrc if it already exist and for greater control.
$ source ~/.zshrc
Comment anonymously. Login not required.