AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 829284
Accepted
somethis
somethis
Asked: 2016-09-25 18:04:42 +0800 CST2016-09-25 18:04:42 +0800 CST 2016-09-25 18:04:42 +0800 CST

用于 Bash / Zsh 的终端多个倒数计时器应用程序

  • 772

我正在寻找一个应用程序来组织我在不同倒数计时器中的日常任务,类似于在www.timeanddate.com/timer/上找到的那个

我正在寻找的功能是:

  • 在终端 bash 或 zsh 中运行
  • 多个独立倒计时
  • 计时器用完后播放声音或通知显示

请注意,时间跟踪不是重要功能,只需倒计时就足够了。

谢谢你。


在此处输入图像描述

bash
  • 4 4 个回答
  • 5797 Views

4 个回答

  • Voted
  1. thom
    2016-10-07T07:44:45+08:002016-10-07T07:44:45+08:00

    从终端使用“at”命令设置您的计时器,“at”非常灵活,因为它可以用于绝对时间和相对时间(更多信息:)man at:

    at now + 1 minute <<<'notify-send ALARM'
    

    “notify-send”将在您的桌面上放置一个通知
    (请随意将其替换为“aplay”以发出声音而不是通知)。

    • 6
  2. Best Answer
    crocket
    2017-04-30T08:03:49+08:002017-04-30T08:03:49+08:00

    您可以将 tmux 或 screen 与 termdown 结合使用。

    Termdown 是一个 ncurses 计时器。

    http://www.slashgeek.net/2016/10/25/termdown-cli-countdown-timer-stopwatch/展示了 termdown 的工作原理。

    tmux 和 screen 允许您一次运行多个倒计时。

    我会制作像这样的脚本

    ~/.bin/pomodoro:
    #!/bin/sh
    termdown 25:00 && mplayer /path/to/sound.mp3
    
    ~/.bin/5minbreak:
    #!/bin/sh
    termdown 05:00 && mplayer /path/to/break.mp3
    

    而且,我将pomodoro在 tmux 或屏幕窗口中执行。这样,我可以创建多个倒计时。

    你想要通知吗?您也可以将通知命令与 termdown 结合使用。

    我会提前为特定的计时器设置多个 tmux 窗口。

    • 1
  3. WinEunuuchs2Unix
    2018-06-24T13:17:11+08:002018-06-24T13:17:11+08:00

    在Ask Ubuntu中有一个名为multi-timer的 bash 脚本

    multi-timer进度条显示

    偷看洗循环.png

    特征

    • 在使用之间保留配置。
    • 最多 19 个定时器在一组中按顺序运行。
    • 每个计时器的进度条。
    • 一组计时器可以运行多次。
    • 设置的进度条。
    • 所有集合的进度条。
    • 启动每个计时器和/或设置的可选提示。
    • 每个计时器和/或设置结束时的可选弹出消息。
    • 每个计时器和/或设置结束时的可选警报。
    • 每个计时器或设置或所有设置结束时的可选锁定屏幕。
    • Sysmonitor Indicator 的可选接口,以便 Systray 显示倒计时。
    • 当所有定时器集结束时,可选的关闭进度条显示。

    访问上面的链接以获取屏幕截图和 bash 代码。

    • 1
  4. Dreamcat4
    2018-06-24T11:39:08+08:002018-06-24T11:39:08+08:00

    今天想出了一个shell函数来为自己解决这个确切的问题。我确实碰巧认为它运作良好。完整的使用说明包含在评论中。

    更新:

    现在需要一个新的依赖项,termdown用于在终端中显示倒数计时器。

    如果您想将此 shell 函数用作脚本,则只需将其复制粘贴到一个新文件中,其中#!/bin/shshebang 作为第 1 行。然后在文件末尾调用该函数timer "$@"以将所有 cmdline 参数传递给它。

    希望这能解决之前提出的批评。

    timer() {
      # tested on ubuntu 18.04
      # installation: copy-paste this shell function into your ~/.bashrc or ~/.profile
    
      # program dependencies
      # to install missing dependancies on ubuntu
      #  # sudo apt-get install -y xcowsay
      #  # sudo snap install -y termdown 
      # this shell function also uses `paplay` (for making a beep / ding sound)
      # and `pgrep` for checking when any xcowsay window was clicked on and dismissed
      # (however on ubuntu desktop 18.04, both `paplay` and `pgrep` are already installed by default)
    
      # usage examples
      # input string is parsed by the unux date command. tested with "date (GNU coreutils) 8.28"
      # ... this version of date seems able to understand and translate these human-readable strings
    
      # timer "1h1m30s"
      # timer "1h 1m 30s"
      # timer "1 minute 30 seconds"
      # timer "15 minutes"
      # timer "2 hours 30 minutes"
    
      # timer "00:45:00" # = "45 minutes"
      # timer "00:00:45" # = "45 seconds"
      # timer "1:1:1"    # = 1 hour, 1 minute and 1 second
    
      # begin
      _time="$1"
      _bell_repeat_delay="3"
    
      # convert input string to seconds, and sleep until time is up
      # _seconds="$(local epoch=$(date --utc -d @0 +%F); date --utc -d "$epoch $time" +%s.%09N)"
    
    
    
      if echo "$_time" | grep -q -E '^[0-9]+$'; then
          _seconds="$_time"
      else
        _date_flag="$(echo "$_time" | sed  -e "s/s/SECONDS/g"  -e "s/m/MINUTES/g"  -e "s/h/HOURS/g")"
        _seconds="$(date -d "1970-01-01 00:00:00 UTC ${_date_flag}" "+%s")"
      fi
    
      _critical="$(echo $_seconds / 10 | bc)"
      if [ $_seconds -lt 60 ]; then
        _critical=20
    
      elif [ $_seconds -lt 100 ]; then
        _critical=30
    
      elif [ $_seconds -lt 200 ]; then
        _critical=40
    
      elif [ $_seconds -lt 300 ]; then
        _critical=60
      fi
    
      # sleep _seconds && \
      termdown --critical $_critical --voice en $_seconds && \
      (
        # handle ctrl+c gracefully
        trap "killall -q xcowsay; exit 1" INT
    
        # display notifications on all monitors, 1 notification per monitor
        i=0; num_monitors="$(xrandr -q| grep " connected" | wc -l)"
        while [ "$i" -lt "$num_monitors" ]; do
    
          # this cmd displays the notification itself, and is further customizable
          xcowsay --monitor=$i --time=0 --cow-size=large "$time is up" &
          i="$(expr $i + 1)"
        done
    
        _sound_file_timer_expired="/usr/share/sounds/gnome/default/alerts/drip.ogg"
        _sound_file_remind_repeat="/usr/share/sounds/freedesktop/stereo/complete.oga"
    
        audacious --pause
        # play -v15 "$_sound_file_timer_expired"
        paplay "$_sound_file_timer_expired"
    
        while true; do
          # detect if any notifications were dismissed, then exit gracefully
          num_cows="$(pgrep -c xcowsay)"
          [ "$(expr $num_monitors - $num_cows)" -gt 0 ] && break
          # make a slowly repeating ding or beep audible alert sound
          paplay "$_sound_file_remind_repeat"
          sleep $_bell_repeat_delay || break
        done
    
        # dismiss all of the notifications, when displayed on multiple monitors
        killall -q xcowsay
        trap - INT
      )
    
    }
    
    • 0

相关问题

  • 同时复制到两个位置

  • 如何在 shell 脚本中创建选择菜单?

  • 从 bash 迁移到 zsh [关闭]

  • bashrc 还是 bash_profile?

  • 备份 bash 脚本未压缩其 tarball

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve