sergey-melnychuk / sergey-melnychuk.github.io

Blog on software engineering
https://sergey-melnychuk.github.io
3 stars 0 forks source link

https://sergey-melnychuk.github.io/2018/06/03/command-prompt-setup/ #28

Closed utterances-bot closed 3 years ago

utterances-bot commented 3 years ago

Command prompt setup

Quite for some time I was taking command prompt for granted, thinking that it is just as it is. But today is the day, I’m setting up the command prompt that I like!

https://sergey-melnychuk.github.io/2018/06/03/command-prompt-setup/

sergey-melnychuk commented 3 years ago

Working alternative for zsh:

# ~/.zshrc
setopt PROMPT_SUBST

get_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ :\1/'
}

export PS1='%n@[%~$(get_git_branch)] $ '

https://superuser.com/questions/142099/get-function-into-ps1-zsh https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html#Prompt-Expansion

sergey-melnychuk commented 10 months ago

Adding colors:

export PS1='\[\033[01;32m\]\u@\[\033[00m\][\[\033[01;34m\]\w\[\033[01;31m\]$(get_git_branch)\[\033[00m\]] $ '