Customize Your Terminal Prompt - SEIR-59/course-wiki GitHub Wiki
The standard prompt, which shows the logged in user and the computer name, is so much information and wasted space for most of us. So, here is how to change that.
Be sure you are in your home directory when doing this. To get there, just type ‘cd’ and return at the prompt.
(you’ll do this once, and then edit this file anytime you wish to add or change any terminal customizations).
touch .zshrc
-
if you have installed the ‘code’ command through VSCode, you can type
code .zshrc
PROMPT=" "
*it should live on it's own line, as should all future customizations
Accepted input
- text (WYSIWYG): will output the text as written
- % flags: insert any combination of the following data (for more, check the source links below)
- %n - $USERNAME
- %m - The hostname up to the first ‘.’
- %. - Current directory (only the folder you are currently in)
- %~ - displays the full directory, and if you are in your user folder, displays ~ instead of username
To see your changes, open a new Terminal window/tab.
To revert to the default prompt, simply delete the PROMPT
line in your .zshrc
file.
The prompt line in the .zshrc
file should read
1 PROMPT='%./: '
Which will make your prompt appear as follows:
"Desktop/: "
Wrap the text you wish to color with %F{123} and %f (where '123' is a 3 digit RGB which you can find here
- Example: to display the current directory as red:
%F{088}%~%f
This is usually more difficult in most areas of code, but it's so simple, it may feel difficult. Simply do what you want: enter a new line (return) and type your PROMPT code over two (or more) lines. So if you wanted to say "Welcome to Harry's Terminal! []: ", you would do:
1 PROMPT="Welcome to Harry's Terminal!
2 ||: "
Advanced Example Showing your Current Directory with Colors, followed by a new line with the clean prompt
The Code:
1 PROMPT="
2 You are in: %F{034}%~/%f
3
4 ||: "
http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html_