Reputation:
I have installed oh-my-zsh and iterm2 on my Mac. Currently the command prompt shows up as currentdirectory@currenthost ~ How can I change it to just show current directory. I tried changing PS1 variable in .bashrc and .bash_profile file to export PS1 = " " but still the prompt remains the same. Any help is appreciated.
Upvotes: 12
Views: 21537
Reputation: 913
Since the update to version 10.15 Catalina, macOS includes Z shell (zsh) as default instead of Bash in the Terminal app, therefore when you install iterm2, it will use any Zsh settings stored on the Zsh profile(dotfile).
Here are the steps to follow; paste the command, save and quit. Reopen iterm2 to view the changes.
By default in MacOS, the dotfile is not there so you'll have to create one.
nano ~/.zshrc
The default Zsh prompt carries information like the username, machine name, and location starting in the user's home directory, so you can customize what to output on prompt:
PROMPT="%n:~$ "
PROMPT="%1d:~$ "
PROMPT="%T:~$ "
PROMPT="%W:~$ "
PROMPT="~$ "
PROMPT="%n:%W:~$ "
PROMPT="%n:%T:~$ "
You can even add coloring to the relevant text. Ensure to enclose in the %F & %f color variables.
PROMPT="%F{cyan}%T%f:~$ "
PROMPT="%F{cyan}%T@%1d%f:~$ "
Upvotes: 16
Reputation: 531
I have tried the following in the iTerm2 + agnoster theme.By default the command prompt shows up as user@hostname.
You should modify the zsh's configuration file:
if you want to show the Home directopry as prompt name, then add these lines to ~/.zshrc:
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$HOME"
fi
}
if you want to show the user as prompt name, then add these lines to ~/.zshrc:
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
fi
}
if you want to show the hostname as prompt name, then add these lines to ~/.zshrc:
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)%m"
fi
}
if you want to completely remove the name then add:
prompt_context() {}
Upvotes: 0
Reputation: 309
Add this line to ~/.zshrc
and it will assume that user on iTerm startup. Then it won't display your username in the prompt.
DEFAULT_USER="your_user_name"
Upvotes: 5