Last active
April 15, 2023 23:27
-
-
Save tyzbit/5f7913f95699fb6f37d7c726ff7a5232 to your computer and use it in GitHub Desktop.
zsh RPROMPT with execution time and current time on the right hand side
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# refreshes the prompt every $TMOUT seconds | |
TMOUT=15 | |
function preexec() { | |
timer=$(($(date +%s%0N)/1000000)) | |
} | |
function precmd() { | |
if [ $timer ]; then | |
now=$(($(date +%s%0N)/1000000)) | |
calculated=$(( $now-$timer )) | |
hours=$(( $calculated/1000/3600 )) | |
min=$(( $calculated/1000/60 )) | |
sec=$(( ($calculated/1000)%60 )) | |
if [[ "${calculated}" -le 1000 ]]; then | |
elapsed="%F{magenta}${calculated}ms" | |
elif [[ "${calculated}" -le 60000 ]]; then | |
elapsed="%F{green}$(( ${calculated} / 1000 ))s" | |
else | |
if [ "$hours" -gt 0 ]; then | |
min="$(( $min%60 ))" | |
elapsed="%F{red}${hours}h${min}m${sec}s" | |
else | |
elapsed="%F{yellow}${min}m${sec}s" | |
fi | |
fi | |
export RPROMPT="[${elapsed}%f] [%F{green}%D{%Y/%m/%d}%f|%F{cyan}%D{%H:%M}%f]" | |
unset timer | |
fi | |
} | |
function TRAPALRM() { | |
case "$WIDGET" in | |
expand-or-complete|self-insert|up-line-or-beginning-search|down-line-or-beginning-search|backward-delete-char|.history-incremental-search-backward|.history-incremental-search-forward|fzf-history-widget) | |
: | |
;; | |
*) | |
zle reset-prompt | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For macs: install
coreutils
and then change alldate
s togdate