执行一个耗时很长的命令时,或命令耗时不确定,可以配置 iTerm2 在命令完成或失败时主动通知,而不用我们自己时不时地去检查。以下是一些获取完成通知的方式。

say

可在命令后跟 say done 来使用声音提示。这里 say 是 mac 上文本转语音的工具,后面跟需要朗读的文本,可以是任意文本。

示例:

$ curl google.com && say done
# 指定人声
$ curl google.com && say -v Ting-Ting done
 

系统通知栏

或者可安装对应工具以生成系统通知。

$ brew install terminal-notifier
# 示例
$ <your job/process command> && echo 'Completed' | terminal-notifier -sound default
 

Shell Integration

不过更加推荐的做法是 Shell Integration。通过 iTerm2 的 Shell Integration 功能可对已经运行中的任务添加提示。因为大多数情况下是执行命令行,等了半天发现耗时不可控,此时添加命令完成的通知就很有用了,比如 brew update

开启方法也很简单,

  • 启用 Shell Integration: iTerm2 -> Install Shell Integration,然后按照指引开启即可。
  • 启用通知,路径为菜单中的 Edit -> Marks and Annotations -> Alerts -> Alert on next mark

iTerm2 中实现命令完成时进行通知

Alert on next mark

开启后右上角会有个瘆人的眼睛????图标,表示提示功能启用中。可通过快捷键快 + + A 快速启用或关闭。

关闭命令行左侧的三角形 ▷

开启 shell integration 后命令行提示符最开始会展示一个三角形符号,看起来不是很美观,

iTerm2 中实现命令完成时进行通知

可在 profile-> terminal -> shell intergration 中关闭:

iTerm2 中实现命令完成时进行通知

完美!

iTerm2 中实现命令完成时进行通知

相关资源

The text was updated successfully, but these errors were encountered:

相关文章:

  • 2022-12-23
  • 2023-01-13
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2021-11-01
猜你喜欢
  • 2021-06-27
  • 2021-07-17
  • 2021-11-25
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案