Skip to content

Instantly share code, notes, and snippets.

@artifactsauce
Last active October 23, 2016 03:35
Show Gist options
  • Save artifactsauce/513b33bac02546f0532885c7a69f11dd to your computer and use it in GitHub Desktop.
Save artifactsauce/513b33bac02546f0532885c7a69f11dd to your computer and use it in GitHub Desktop.
BitBarで自分の人生の残り時間を常に意識する ref: http://qiita.com/artifactsauce/items/1caca90e91c6ca90ebbf
$ date --date="2055-10-01 23:56:45 1 year -46 days"
水 8 16 23:56:45 JST 2056
#!/usr/bin/env bash
# <bitbar.title>The rest of your life.</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Kenji Akiyama</bitbar.author>
# <bitbar.author.github>artifactsauce</bitbar.author.github>
# <bitbar.desc>The rest of your life.</bitbar.desc>
# <bitbar.image>https://qiita-image-store.s3.amazonaws.com/0/5823/a36947b1-27b4-826d-e6a5-366c2f494511.png</bitbar.image>
# <bitbar.dependencies>coreutils</bitbar.dependencies>
set -eu
# Must Edit this
BIRTH_DATE="1980-04-01 18:00"
# Edit if you want
AVERAGE_LONGEVITY=80
FONT_FACE="Menlo"
MENUBAR_ICON=":older_man:"
# Don't edit
DATE_CMD="/usr/local/opt/coreutils/libexec/gnubin/date" # installed by Homebrew
# 生存日数
ELAPSED_DAYS=$(( ($($DATE_CMD "+%s") - $($DATE_CMD --date "$BIRTH_DATE" "+%s")) / 86400 ))
# 生存時間
ELAPSED_HOURS=$(( ($($DATE_CMD "+%s") - $($DATE_CMD --date "$BIRTH_DATE" "+%s")) / 3600))
# 予定死亡日数
LONGEVITY_DAYS=$(( ($($DATE_CMD --date "$AVERAGE_LONGEVITY years" "+%s") - $($DATE_CMD "+%s")) / 86400))
# 予定死亡時間
LONGEVITY_HOURS=$(( ($($DATE_CMD --date "$AVERAGE_LONGEVITY years" "+%s") - $($DATE_CMD "+%s")) / 3600))
echo "$MENUBAR_ICON"
echo "---"
echo "Elapsed: | color=black font=$FONT_FACE"
printf "* %6d days | color=gray font=$FONT_FACE\n" $ELAPSED_DAYS
printf "* %6d hours | color=gray font=$FONT_FACE\n" $ELAPSED_HOURS
echo "Remained: | color=black font=$FONT_FACE"
printf "* %6d days | color=orange font=$FONT_FACE\n" $(( $LONGEVITY_DAYS - $ELAPSED_DAYS ))
printf "* %6d hours | color=orange font=$FONT_FACE\n" $(( $LONGEVITY_HOURS - $ELAPSED_HOURS ))
printf "* %6.1f %% | color=red font=$FONT_FACE\n" $(echo "scale=1; 100 * ($LONGEVITY_HOURS - $ELAPSED_HOURS) / $LONGEVITY_HOURS"| bc)
echo "---"
echo "Refresh | refresh=true color=#C0C0C0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment