# Prompt NEWLINE=$'\n' ARROW=$'\UE0B0' setopt prompt_subst function _git_symbols() { # Symbols local ahead='↑' local behind='↓' local diverged='↕' local up_to_date='|' local no_remote='' local staged='+' local untracked='?' local modified='!' local moved='>' local deleted='x' local stashed='$' local output_symbols='' local git_status_v git_status_v="$(git status --porcelain=v2 --branch --show-stash 2>/dev/null)" # Parse branch information local ahead_count behind_count # AHEAD, BEHIND, DIVERGED if echo $git_status_v | grep -q "^# branch.ab " ; then # One line of the git status output looks like this: # # branch.ab +1 -2 # In the line below: # - we grep for the line starting with # branch.ab # - we grep for the numbers and output them on separate lines # - we remove the + and - signs # - we put the two numbers into variables, while telling read to use a newline as the delimiter for reading read -d "\n" -r ahead_count behind_count <<< $(echo "$git_status_v" | grep "^# branch.ab" | grep -o -E '[+-][0-9]+' | sed 's/[-+]//') # Show the ahead and behind symbols when relevant [[ $ahead_count != 0 ]] && output_symbols+="$ahead" [[ $behind_count != 0 ]] && output_symbols+="$behind" # Replace the ahead symbol with the diverged symbol when both ahead and behind output_symbols="${output_symbols//$ahead$behind/$diverged}" # If the branch is up to date, show the up to date symbol [[ $ahead_count == 0 && $behind_count == 0 ]] && output_symbols+="$up_to_date" fi # STASHED echo $git_status_v | grep -q "^# stash " && output_symbols+="$stashed" # STAGED [[ $(git diff --name-only --cached) ]] && output_symbols+="$staged" # For the rest of the symbols, we use the v1 format of git status because it's easier to parse. local git_status symbols="$(git status --porcelain=v1 | cut -c1-2 | sed 's/ //g')" while IFS= read -r symbol; do case $symbol in ??) output_symbols+="$untracked";; M) output_symbols+="$modified";; R) output_symbols+="$moved";; D) output_symbols+="$deleted";; esac done <<< "$symbols" # Remove duplicate symbols output_symbols="$(echo -n "$output_symbols" | tr -s "$untracked$modified$moved$deleted")" [[ -n $output_symbols ]] && echo -n " $output_symbols" } function _git_info() { local git_info='' local git_branch_name='' if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then git_branch_name="$(git symbolic-ref --short HEAD 2>/dev/null)" if [[ -n "$git_branch_name" ]]; then git_info+="%K{202}%F{52}${ARROW}%f" git_info+="%F{black}%B " git_info+="ש $git_branch_name" fi git_info+="$(_git_symbols)" git_info+="%b%f" git_info+="%k%F{202}${ARROW}%f" echo "$git_info " else git_info+="%K{black}%F{52}${ARROW}%f%k" echo "$git_info " fi } # Set background and foreground for first element PROMPT='%K{214}%F{black}' # Print date and time PROMPT+='${ARROW} %D %T ' # Close first element PROMPT+='%f%k' # Set background for second element PROMPT+='%K{52}' # Print next arrow PROMPT+='%F{214}${ARROW}%f' # Print current and parent directory PROMPT+=' %2d ' # Close second element PROMPT+='%k' # Git Status PROMPT+='$(_git_info)' # Move to new line PROMPT+='${NEWLINE}' # Start second line PROMPT+=' > ' # Composer export PATH="$HOME/.composer/vendor/bin:$PATH" # Homebrew export PATH="/usr/local/sbin:$PATH" # Node.js ## NVM export NVM_DIR="$HOME/.nvm" ### Load NVM [ -s "$(brew --prefix)/opt/nvm/nvm.sh" ] && \. "$(brew --prefix)/opt/nvm/nvm.sh" ### Load bash completion [ -s "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" ] && \. "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" # Python ## pyenv export PYENV_ROOT="$HOME/.pyenv" ### pyenv setup [[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" ## pipx export PATH="$PATH:/~/.local/bin"