Skip to content

Instantly share code, notes, and snippets.

@KristianLyng
Created June 16, 2015 08:13
Show Gist options
  • Select an option

  • Save KristianLyng/66901ce11a0450107724 to your computer and use it in GitHub Desktop.

Select an option

Save KristianLyng/66901ce11a0450107724 to your computer and use it in GitHub Desktop.
#!/bin/bash
NOW=$(date +%s)
WEEKEND=$(date -d 'friday 16:00:00' +%s)
FRIDAY=$(date -d 'friday 00:00:00' +%s)
DIFF=$(( ${FRIDAY} - ${NOW} ))
DIFFD=$(( ${DIFF} / 86400 ))
DIFFH=$(( (${DIFF} - ${DIFFD}*86400) / 3600 ))
DIFFM=$(( (${DIFF} - ${DIFFD}*86400 - ${DIFFH}*3600) / 60 ))
DIFFW=$(( ${WEEKEND} - ${NOW} ))
DIFFWD=$(( ${DIFFW} / 86400 ))
DIFFWH=$(( (${DIFFW} - ${DIFFWD}*86400) / 3600 ))
DIFFWM=$(( (${DIFFW} - ${DIFFWD}*86400 - ${DIFFWH}*3600) / 60 ))
mode=$(basename $0 | sed s/\.sh//)
if [ "x$1" != "x" ]; then
mode=$1
fi
if [ $mode = "friday" ]; then
echo "$DIFFD days, $DIFFH hours, $DIFFM minutes until Friday!"
elif [ $mode = "fredag" ]; then
echo "$DIFFD dager, $DIFFH timer, $DIFFM minutter til fredag!"
elif [ $mode = "weekend" ]; then
echo "$DIFFWD days, $DIFFWH hours, $DIFFWM minutes until the weekend!"
elif [ $mode = "helg" ]; then
echo "$DIFFWD dager $DIFFWH timer $DIFFWM minutter til helgen er her!"
else
echo "Jokkmokk! Try $0 friday, or $0 weekend, or $0 helg or $0 fredag"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment