从.bashrc执行定时命令
我正在尝试创建自己的最小bash shell提示,以使每个命令的执行时间执行。到目前为止,我有一个功能上的提示,看起来很吸引我的欲望。我只是错过了时间输出,例如 starship 。我尝试使用time
而无需成功的时候,我尝试从$@,$*,$*,/dev/stdin读取用户输入。我还尝试在脚本开头使用date
,并在将差异减去相似的影响时结束。无论我尝试过什么,执行时机总是关闭或根本不起作用。我已经检查了文档和几个网站以获取建议,但没有一个
我得到的最接近的结果是在下面使用此片段
function timer_start {
timer=${timer:-$SECONDS}
}
function timer_stop {
timer_show=$(($SECONDS - $timer))
unset timer
}
trap 'timer_start' DEBUG
PROMPT_COMMAND=timer_stop
PS1="$ ${timer_show}s "
I'm trying to create my own minimal BASH shell prompt that times execution of each command entered. So far I have a functional prompt that looks appealing for my desires; I'm just missing the time output, like starship does. I've tried reading user input from $@, $*, /dev/stdin while using time
without success. I also tried using date
at the start of the script and end while subtracting the difference to a similar affect. No matter what I've tried the execution timing is always off or doesn't work at all. I've checked documentation and several sites for suggestions but none worked
The closest result I got was using this snippet below
function timer_start {
timer=${timer:-$SECONDS}
}
function timer_stop {
timer_show=$(($SECONDS - $timer))
unset timer
}
trap 'timer_start' DEBUG
PROMPT_COMMAND=timer_stop
PS1="$ ${timer_show}s "
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
提出了 @ kamilcuk - 我能够从.bashrc工作的功能计时器!当前,它会闲置/打字 +命令执行时间(我认为我还是喜欢)
With suggestions from @KamilCuk - I was able to get a functioning timer working from .bashrc! Currently it gets idle/typing + command execution time (which I think I prefer anyway)