SEANK.H.LIAO

zsh prompt

things i found useful in zsh prompt

prompt

Maybe one day I'll get back to being a minimalist and just use $ or # or ;, but right now I'm liking my custom prompt, loosely based on sindresorhus/pure.

122:49:16 ~ 0:00:00
2»

bit by bit

 1#!/usr/bin/env zsh
 2
 3export PROMPT_EOL_MARK=''
 4
 5function _preexec() {
 6    typeset -g prompt_timestamp=$EPOCHSECONDS
 7}
 8
 9function _precmd() {
10    integer elapsed=$(( EPOCHSECONDS - ${prompt_timestamp:-$EPOCHSECONDS} ))
11    local human="$(( elapsed / 3600 )):${(l:2::0:)$(( elapsed / 60 % 60 ))}:${(l:2::0:)$(( elapsed % 60 ))}"
12    vcs_info
13    local newline=$'\n%{\r%}'
14
15    PROMPT="${newline}%F{green}%*%f %F{blue}%~%f %F{yellow}${human}%f${newline}"
16    PROMPT+="%F{242}${STY:+screen-}${VIRTUAL_ENV:+venv-}${vcs_info_msg_0_:+${vcs_info_msg_0_} }%f"
17    PROMPT+="%(?.%F{magenta}.%F{red})${SSH_CONNECTION+%n@%m}»%f "
18}
19
20add-zsh-hook precmd  _precmd
21add-zsh-hook preexec _preexec