Last active
October 29, 2025 21:55
-
-
Save sorbits/5c0cb7292de091253f8e to your computer and use it in GitHub Desktop.
Revisions
-
sorbits revised this gist
Aug 21, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,10 +8,9 @@ function create_hash { openssl dgst -sha1 -binary <<< "$1" | xxd -p } while getopts ':n:vh' opt; do case $opt in n) step=$OPTARG ;; v) echo "$progname $version"; exit ;; :) echo >&2 "$progname: option requires an argument -- $OPTARG"; exit 1 ;; \?) echo >&2 "$progname: illegal option: -- $OPTARG"; exit 1 ;; -
sorbits created this gist
Aug 17, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ #!/usr/bin/env bash progname=$(basename $0) version="1.0 (2014-08-17)" step=2 function create_hash { openssl dgst -sha1 -binary <<< "$1" | xxd -p } while getopts ':n:c:vh' opt; do case $opt in n) step=$OPTARG ;; c) cmd=$OPTARG ;; v) echo "$progname $version"; exit ;; :) echo >&2 "$progname: option requires an argument -- $OPTARG"; exit 1 ;; \?) echo >&2 "$progname: illegal option: -- $OPTARG"; exit 1 ;; h) echo "$progname $version" echo "Usage: $progname [-n number] command [argument ...]" echo " $progname [-v|-h]" echo "Options:" echo " -n <number> Run every <number> time. Defaults to 2." echo " -v Print version information." echo " -h Show this information." exit ;; esac done if [ $OPTIND -gt $# ]; then echo >&2 "$progname: no command specified. Use -h for usage options." exit 1 fi file="${XDG_DATA_HOME:-$HOME/.local/share}/${progname}/$(create_hash "$*")" if [ ! -f "$file" ]; then mkdir -p "$(dirname "$file")" echo >"$file" 1 fi value=$(head -n1 "$file") if [ $value -ge $step ]; then rm "$file" exec "${@:$OPTIND}" fi printf "%d\n# Last run: %s\n# Command: %s\n" "$(( $value + 1 ))" "$(date)" "${*:$OPTIND}" >"$file"