git.slaskete.net
/
einar-bin
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
La til en parser for å gjøre det enklere å scanne farger med Linshang LS171
[einar-bin]
/
imgurgame.bash
diff --git
a/imgurgame.bash
b/imgurgame.bash
index ef098412d8497224838be38ba1f697a814d7d67d..a30b02d5662ea45844dcb5897c1ddb9c2bfa2ea8 100755
(executable)
--- a/
imgurgame.bash
+++ b/
imgurgame.bash
@@
-6,8
+6,10
@@
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
# 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))
+ STRLN=$((5 +
RANDOM
% 3))
local ID
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"
}
ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${STRLN} | head -n 1)
echo "http://i.imgur.com/${ID}.jpg"
}
@@
-16,7
+18,7
@@
imgururl() {
testimgur() {
local URL=${1}
local RESULT
testimgur() {
local URL=${1}
local RESULT
- RESULT=$(curl -s -o /dev/null -I -w "%{http_code}"
${URL}
)
+ RESULT=$(curl -s -o /dev/null -I -w "%{http_code}"
"${URL}"
)
if [[ ${RESULT} == "200" ]]; then
echo true
else
if [[ ${RESULT} == "200" ]]; then
echo true
else
@@
-29,9
+31,9
@@
main() {
while true; do
local URL
URL=$(imgururl)
while true; do
local URL
URL=$(imgururl)
- if [[ $(testimgur
${URL}
) == "true" ]]; then
+ if [[ $(testimgur
"${URL}"
) == "true" ]]; then
echo "Found ${URL} after ${FAIL} failed tries"
echo "Found ${URL} after ${FAIL} failed tries"
- ${BROWSER}
${URL}
> /dev/null 2>&1
+ ${BROWSER}
"${URL}"
> /dev/null 2>&1
local FAIL=0
else
((FAIL++))
local FAIL=0
else
((FAIL++))