LoginSignup
0
2

More than 3 years have passed since last update.

【fish】Mac ターミナル上でカウントダウンタイマー

Posted at

こんな感じ

#入力値調整
read -P "How many minutes? >" input;
set error_message "--------------------------------------"\n"please set numbers 1 ≦ [input] ≦ 120!!"\n"--------------------------------------";
set input_time (expr $input - 1);
​
#このタイマーは1分未満を測れません!
​
if test $status -eq 2;
 echo $error_message;
 exit;
else if test $input_time -lt 0;
 echo $error_message;
 exit;
else
 echo "-------------------"\n"start["{$input}"]minutes!!"\n"-------------------";
end;
​
#n分* 59 sleep_loop
for mm in (seq $input_time 1);
​
 for ss in (seq 59 0);

  sleep 1;clear;

  #1桁分の場合、先頭に0を追加
  if test $mm -le 9;
   echo -n 0;
  end;
​
  echo -n $mm:;

  #1桁秒の場合、先頭に0を追加
  if test $ss -le 9;
   echo -n 0;
  end;

  echo $ss;
  end;

  if test $mm -eq 0 -a $ss -eq 0;
   break;
  end;
​
  echo "-------";
  echo "finish!";
  echo "-------";
​
end;

おまけ

※不具合ありワンライナー版(残り1分で止まります)
※※使い道がないので修正はしていません

for mm in (seq 3 1); for ss in (seq 59 0); sleep 1; clear ;  if test $mm -le 9; echo -n 0; end; echo -n $mm:; if test $ss -le 9; echo -n 0; end; echo $ss; end; if test $mm -eq 0 -a $ss -eq 0; break; end; end;

なんでこんなものを作ったのか

ScaraMatsuri2020のスタッフとして参加した10/18
タイムキーパーだったのでZoomにて仮想カメラを用いてタイマーを映す必要がありました。

しかしタイマーが映せない+タイマーアプリそのものも起動できないなどトラブルが発生
前日は大丈夫だったのに・・・。

色々思考錯誤しターミナル画面は映せたのでこれでなんとかできるのでは・・・
と思ったのですがなんだかんだ解決したのでお蔵入りしました。

後日.shとして作り直したのがこちらでございます。
※ifとforはbashだと若干書き方違うので、流用する場合はその辺りちょっと調べてみてください。

カウントアップでもよければ

// 現在時刻表示 1秒ごとに更新
watch -n 1 date

//例 オプション付けてみたり
watch -n 1 date -v-1H +%M:%S 

で、より簡単に見れます。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2