oh-my-zsh
顯示執行時間
進入主題目錄~/.oh-my-zsh/themes
在想要修改的主題文件中添加如下代碼:
function preexec() {
timer=${timer:-$SECONDS}
}
function precmd() {
if [ $timer ]; then
timer_show=$(($SECONDS - $timer))
if [[ $timer_show -ge $min_show_time ]]; then
RPROMPT='%{$fg_bold[red]%}(${timer_show}s)%f%{$fg_bold[white]%}[%*]%f'
else
RPROMPT='%{$fg_bold[white]%}[%*]%f'
fi
unset timer
fi
}
autoload -Uz add-zsh-hook
add-zsh-hook preexec preexec
add-zsh-hook precmd precmd
默認主題robbyrussell
效果圖:
附上一個修改好主題文件:oh-my-zsh默認主題robbyrussell執行時間版
Reference
- https://note.pcwu.net/2017/03/25/zsh-theme-execution-time/