Apple changed shell from bash
to zsh
in its latest OS, so I'm trying to fix my Terminal prompt now :(.
I would like my prompt to only contain:
~
if I'm in the home directory$
and a space at the endI used to have this script in my .bash_profile
when I was using bash
:
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\[\033[33;1m\]\W\[\033[32m\]\$(parse_git_branch)\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
I renamed .bash_profile
into .zprofile
, but all this is not working anymore except for the ls
part.
How do I make this work again?
So after more googling and looking into a specific part of zsh
manual which could be shown by running man zshmisc
I managed to fix this. Here is the code for .zprofile
:
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '%b'
# Set up the prompt
setopt PROMPT_SUBST
PROMPT='%1~ %F{green}${vcs_info_msg_0_}%f $ '
%1~
means that only one last trailing component of the current working directory will be shown, and the home directory will be substituted with ~
.
This is my .zshrc
based on Sergey's great answer. It enhances it by adding some more color and colon separated branch names (only if available).
This also works smooth for the integrated terminals in JetBrains IDE's (IntelliJ / PhpStorm / WebStorm).
# load version control information
autoload -Uz vcs_info
precmd() { vcs_info }
# format vcs_info variable
zstyle ':vcs_info:git:*' formats ':%F{green}%b%f'
# set up the prompt
setopt PROMPT_SUBST
PROMPT='%F{blue}%1~%f${vcs_info_msg_0_} $ '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With