Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/kasper9n/my-bash-scripts. My personal bash scripts
Something went wrong. Try again.
1.3 kB · 49 lines
at master
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950#! /bin/bash
help() { echo "Do nothing for some time. Useful for scheduling stuff." echo "" echo "`color 2 Examples:`" echo " chill 1h" echo " chill 30m 2s" echo " chill 1s 10s 10h 60m" echo ""}
TOTAL_SECONDS=0
# no argsif [[ "$#" < 1 ]]; then help; exit 0; fi
# parse argsfor (( i=1; i <= "$#"; i++ )); do ARG="${!i}" if [[ $ARG == *s ]]; then TOTAL_SECONDS=$(($TOTAL_SECONDS + ${ARG%s})) elif [[ $ARG == *sec ]]; then TOTAL_SECONDS=$(($TOTAL_SECONDS + ${ARG%sec})) elif [[ $ARG == *m ]]; then TOTAL_SECONDS=$(($TOTAL_SECONDS + ${ARG%m} * 60)) elif [[ $ARG == *min ]]; then TOTAL_SECONDS=$(($TOTAL_SECONDS + ${ARG%min} * 60)) elif [[ $ARG == *h ]]; then TOTAL_SECONDS=$(($TOTAL_SECONDS + ${ARG%h} * 3600)) else help exit 0 fidone
HOURS=$(( ($TOTAL_SECONDS / 60 / 60) ))MINUTES=$(( ($TOTAL_SECONDS / 60) % 60 ))SECONDS=$(( $TOTAL_SECONDS % 60 ))
TOTAL_SECONDS=$(($SECONDS + $MINUTES*60 + $HOURS*3600))if [[ $HOURS != 0 ]]; then echo "Sleeping for ${HOURS}h ${MINUTES}m ${SECONDS}s ($TOTAL_SECONDS seconds)"elif [[ $MINUTES != 0 ]]; then echo "Sleeping for $MINUTES minutes, $SECONDS seconds ($TOTAL_SECONDS seconds)"elif [[ $SECONDS != 0 ]]; then echo "Sleeping for $SECONDS seconds"fisleep $TOTAL_SECONDS