Inspired by: Add Git Branch Name to Terminal Prompt
I have a two line zsh prompt:
- line 1: current-directory
[git branch]
- line 2: hostname
HH:MM:SS
$
In my .zshrc
file:
function parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF=$'%f'
COLOR_DATE=$'%F{243}'
COLOR_DIR=$'%F{197}'
COLOR_GIT=$'%F{39}'
setopt PROMPT_SUBST
PROMPT_CWD='${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}'
export NEWLINE=$'\n'
export PROMPT="${NEWLINE}${PROMPT_CWD}${NEWLINE}${COLOR_DATE}%m %D{%H:%M:%S}${COLOR_DEF} $ "
Here is what it looks like, with the directory name in red, the branch in blue, and the date in faded gray:
~/go/src/github.com/jftuga/dtdiff [dev]
mac 17:35:28 $
What I like about having the time:
- If I meant to time something, but forgot to, I have a built-in timer of sorts
- I can easily scroll back to see how long ago I ran a command