i use arch btw
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add simple stopwatch

from https://github.com/coryfklein/sw

+65
+65
bin/bin/sw
··· 1 + #!/usr/bin/env bash 2 + set -e 3 + 4 + # Usage: 5 + # sw 6 + # - start a stopwatch from 0, save start time 7 + # sw [-r|--resume] 8 + # - start a stopwatch from the last saved start time (or current time if no last saved start time exists) 9 + # - "-r" stands for --resume 10 + 11 + function finish { 12 + tput cnorm # Restore cursor 13 + exit 0 14 + } 15 + 16 + trap finish EXIT 17 + 18 + # Use GNU date if possible as it's most likely to have nanoseconds available. 19 + if hash gdate 2>/dev/null; then 20 + GNU_DATE=gdate 21 + elif date --version | grep 'GNU coreutils' >/dev/null; then 22 + GNU_DATE=date 23 + fi 24 + 25 + function datef { 26 + if [[ -z "$GNU_DATE" ]]; then 27 + date "$@" 28 + else 29 + $GNU_DATE "$@" 30 + fi 31 + } 32 + 33 + # Display nanoseconsd only if supported 34 + if datef +%N | grep -q N 2>/dev/null; then 35 + DATE_FORMAT="+%H:%M:%S" 36 + else 37 + DATE_FORMAT="+%H:%M:%S.%N" 38 + NANOS_SUPPORTED=true 39 + fi 40 + 41 + tput civis # hide cursor 42 + 43 + # If -r is passed, use saved start time from ~/.sw 44 + if [[ "$1" == "-r" || "$1" == "--resume" ]]; then 45 + if [[ ! -f $HOME/.sw ]]; then 46 + datef +%s > $HOME/.sw 47 + fi 48 + START_TIME=$(cat $HOME/.sw) 49 + else 50 + START_TIME=$(datef +%s) 51 + echo -n $START_TIME > $HOME/.sw 52 + fi 53 + 54 + # GNU date accepts the input date differently than BSD 55 + if [[ -z "$GNU_DATE" ]]; then 56 + DATE_INPUT="-v-${START_TIME}S" 57 + else 58 + DATE_INPUT="--date now-${START_TIME}sec" 59 + fi 60 + 61 + while [ true ]; do 62 + STOPWATCH=$(TZ=UTC datef $DATE_INPUT $DATE_FORMAT | ( [[ "$NANOS_SUPPORTED" ]] && sed 's/.\{7\}$//' || cat ) ) 63 + printf "\r\e%s" $STOPWATCH 64 + sleep 0.03 65 + done