oh-my-zsh
主题显示执行时间
- 附上一个修改好主题文件:oh-my-zsh默认主题robbyrussell执行时间版
一键安装
wget -O ~/.oh-my-zsh/themes/robbyrussell.zsh-theme https://raw.githubusercontent.com/icpd/robbyrussell.zsh-theme/master/robbyrussell.zsh-theme
进入主题目录~/.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 %{$reset_color%}%'
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
Reference
- https://note.pcwu.net/2017/03/25/zsh-theme-execution-time/