X-Git-Url: https://git.slaskete.net/einar-bin/blobdiff_plain/dd12cf43d2c38d6d15c45f75523413a18d16952a..cc4676f281200e14e3c00f504603b307ed6ed7d5:/imgurgame.bash?ds=sidebyside diff --git a/imgurgame.bash b/imgurgame.bash index 7635929..a30b02d 100755 --- a/imgurgame.bash +++ b/imgurgame.bash @@ -5,16 +5,20 @@ readonly BROWSER="google-chrome" # Create a random imgur url that may or may not be valid imgururl() { - # 1/3% chance for length of 5, 6 or 7 length string - STRLN=$((5 + ${RANDOM} % 3)) - local ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${STRLN} | head -n 1) + # 1/3 chance for length of 5, 6 or 7 length string + STRLN=$((5 + RANDOM % 3)) + local ID + # don't nag about useless cat, this is more readable + # shellcheck disable=2002 + ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${STRLN} | head -n 1) echo "http://i.imgur.com/${ID}.jpg" } # Test if we found a valid URL testimgur() { local URL=${1} - local RESULT=$(curl -s -o /dev/null -I -w "%{http_code}" ${URL}) + local RESULT + RESULT=$(curl -s -o /dev/null -I -w "%{http_code}" "${URL}") if [[ ${RESULT} == "200" ]]; then echo true else @@ -25,13 +29,14 @@ testimgur() { main() { local FAIL=0 while true; do - local URL=$(imgururl) - if [[ $(testimgur ${URL}) == "true" ]]; then + local URL + URL=$(imgururl) + if [[ $(testimgur "${URL}") == "true" ]]; then echo "Found ${URL} after ${FAIL} failed tries" - ${BROWSER} ${URL} > /dev/null 2>&1 + ${BROWSER} "${URL}" > /dev/null 2>&1 local FAIL=0 else - FAIL=$(( ${FAIL}+1 )) + ((FAIL++)) fi done }