Skip to content

Commit

Permalink
Added .zshrc customization for git branch and status
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinkya-k committed May 13, 2024
1 parent f68f86a commit 71d422a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,35 @@ for x in "${@:-.}"; do
done

```

# Prompt coloring for macOS ZSH

The snippet below modifies the `zsh` prompt by setting a green color for the name (hardcoded to my name here), magenta for path (only shows current folder name), followed by git branch name (if any) color coded by status.
This is basically just a copy of [this template](https://gist.github.com/chrisnolet/d3582cd63eb3d7b4fcb4d5975fd91d04) by [Chris Nolet](https://gist.github.com/chrisnolet) but with slight modifications for my own purposees.
To use, add the following lines to `.zshrc`:

```zsh
autoload -Uz compinit && compinit
autoload -Uz add-zsh-hook
autoload -Uz vcs_info

add-zsh-hook precmd vcs_info

zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' formats " %F{cyan}%c%u(%b)%f"
zstyle ':vcs_info:*' actionformats " %F{cyan}%c%u(%b)%f %a"
zstyle ':vcs_info:*' stagedstr "%F{green}"
zstyle ':vcs_info:*' unstagedstr "%F{red}"
zstyle ':vcs_info:*' check-for-changes true

zstyle ':vcs_info:git*+set-message:*' hooks git-untracked

+vi-git-untracked() {
if git --no-optional-locks status --porcelain 2> /dev/null | grep -q "^??"; then
hook_com[staged]+="%F{red}"
fi
}

setopt PROMPT_SUBST
export PROMPT='%F{green}ajinkya%f:%F{magenta}%1~%f$vcs_info_msg_0_ %# '
```

0 comments on commit 71d422a

Please sign in to comment.