Skip to content

Instantly share code, notes, and snippets.

@MadaShindeInai
Last active January 5, 2024 09:15
Show Gist options
  • Save MadaShindeInai/aa600b9ad791230556bbf3572259c738 to your computer and use it in GitHub Desktop.
Save MadaShindeInai/aa600b9ad791230556bbf3572259c738 to your computer and use it in GitHub Desktop.
ZSH terminal config

Conveniently illuminated ZSH terminal

macOS:

  1. Open terminal
  2. Write there open ~/.zshrc
  3. If file do not exist write touch ~/.zshrc and open ~/.zshrc again
  4. Insert code below
function parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}

setopt PROMPT_SUBST
export PROMPT='%{%B%F{38}%}[%D{%H:%M:%S}]%{%f%b%} %{%B%F{135}%}%~%{%f%b%} %{%B%F{156}%}$(parse_git_branch)%{%f%b%} %{%F{normal}%}=)%{%f%} '

TMOUT=1

TRAPALRM() {
    zle reset-prompt
}

What this code do:

  1. Makes your PROMPT colored.
  2. Build PROMPT line that consist of realtime-clock, working directory and git branch.

Screenshot 2022-05-22 at 23 33 28

Tips:

  1. You should follow %{%B%F{38}%}[%D{%H:%M:%S}]%{%f%b%} structure, so string will be correctly parsed.
  2. F - means Color. B - means Bold. S - means BGColor.
  3. Remove something like "terminal.integrated.defaultProfile.osx": "bash" from your VSCode settings.json to enable ZSH there.
  4. Set ZSH as default editor: chsh -s $(which zsh)
  5. %{%B%F{135}%}%~%{%f%b%} => ~ - means directory path. Put c instead ~ to show only folder.Screenshot 2022-05-22 at 23 00 05
  6. 38, 135 and 156 are colors. You can change it depending on your preferences using palette below. UQVe5

Connected Gists/Materials:

  1. https://gist.github.com/reinvanoyen/05bcfe95ca9cb5041a4eafd29309ff29
  2. https://gist.github.com/doubleknd26/c4fcd2e65c3397947248878065b644ed
  3. https://gist.github.com/jasonm23/2868981
  4. https://zsh-prompt-generator.site/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment