From ea12a398d8c776c7b3b212022fe25ffdcfcd9163 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Mon, 9 Mar 2020 16:04:39 +0800 Subject: [PATCH 1/3] hangover: lint the shell * arrays are bash-only features * `$[]` is crazy outdated * `[ -gt ]` is boring when you have the straight arithmetic operator stuff --- hangover.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hangover.sh b/hangover.sh index 800a182..d3ab4c8 100755 --- a/hangover.sh +++ b/hangover.sh @@ -1,7 +1,7 @@ -#!/bin/sh -e +#!/bin/bash -e # Exit early if any session with my username is found -if who | grep -wq $USER; then +if who | grep -wq "^$USER"; then exit fi @@ -15,18 +15,19 @@ EXCUSES=( 'Food poisoning' 'Not feeling well' ) -rand=$[ $RANDOM % ${#EXCUSES[@]} ] +rand=$(( RANDOM % ${#EXCUSES[@]} )) RANDOM_EXCUSE=${EXCUSES[$rand]} MESSAGE="Gonna work from home. "$RANDOM_EXCUSE # Send a text message -RESPONSE=`curl -fSs -u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" \ +RESPONSE=$(curl -fSs -u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" \ -d "From=$MY_NUMBER" -d "To=$NUMBER_OF_BOSS" -d "Body=$MESSAGE" \ - "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages"` + "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages") # Log errors -if [ $? -gt 0 ]; then +if (( $? > 0 )); then echo "Failed to send SMS: $RESPONSE" exit 1 fi + From 0b066446d67b26119cf7c5fd5cd9bbb50f71c59b Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Mon, 9 Mar 2020 16:08:16 +0800 Subject: [PATCH 2/3] bitch.sh: same change --- smack-my-bitch-up.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/smack-my-bitch-up.sh b/smack-my-bitch-up.sh index cc0547c..18e1c7f 100755 --- a/smack-my-bitch-up.sh +++ b/smack-my-bitch-up.sh @@ -1,7 +1,7 @@ -#!/bin/sh -e +#!/bin/bash -e # Exit early if no sessions with my username are found -if ! who | grep -wq $USER; then +if ! who -q | grep -wFq "$USER"; then exit fi @@ -14,18 +14,18 @@ REASONS=( 'Gotta ship this feature' 'Someone fucked the system again' ) -rand=$[ $RANDOM % ${#REASONS[@]} ] +rand=$(( RANDOM % ${#REASONS[@]} )) RANDOM_REASON=${REASONS[$rand]} MESSAGE="Late at work. "$RANDOM_REASON # Send a text message -RESPONSE=`curl -fSs -u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" \ +RESPONSE=$(curl -fSs -u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" \ -d "From=$MY_NUMBER" -d "To=$HER_NUMBER" -d "Body=$MESSAGE" \ - "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages"` + "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages") # Log errors -if [ $? -gt 0 ]; then +if (( $? )); then echo "Failed to send SMS: $RESPONSE" exit 1 fi From dff194577e6b44ea89127063617c6f17e7fde0c6 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Mon, 9 Mar 2020 16:09:09 +0800 Subject: [PATCH 3/3] hangover: same grep stuff --- hangover.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hangover.sh b/hangover.sh index d3ab4c8..c14d9fb 100755 --- a/hangover.sh +++ b/hangover.sh @@ -1,7 +1,7 @@ #!/bin/bash -e # Exit early if any session with my username is found -if who | grep -wq "^$USER"; then +if who -q | grep -wqF "$USER"; then exit fi