Skip to content

Commit

Permalink
Resolve all ShellCheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
strafe committed Feb 4, 2024
1 parent 6bb9503 commit c844518
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions grumi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

# grumi
# 🖼️ Upload an image, video or album to Imgur via the command line.
readonly program="$(basename "$0")"
readonly version=0.7.0
program="$(basename "$0")"
version=0.7.0
readonly program version

function process_arguments() {
# If no arguments are supplied.
Expand Down Expand Up @@ -59,7 +60,8 @@ function depends_on() {
function check_id() {
if [ -z "$client_id" ]; then
if [ -f "${XDG_CONFIG_HOME:-"${HOME}"/.config}/grumi/client_id" ]; then
readonly client_id="$(<"${XDG_CONFIG_HOME:-"${HOME}"/.config}/grumi/client_id")"
client_id="$(<"${XDG_CONFIG_HOME:-"${HOME}"/.config}/grumi/client_id")"
readonly client_id
fi

if [ -z "$client_id" ]; then
Expand Down Expand Up @@ -172,7 +174,8 @@ function upload_file() {

# Error handling is tricky as the returned JSON is not consistent (sometimes data.error is an object).
if [[ "$(jq -r '.success' <<< "$response")" == false ]]; then
local error="$(jq -r '.data.error.message' 2>/dev/null <<< "$response")"
local error
error="$(jq -r '.data.error.message' 2>/dev/null <<< "$response")"
if [ -z "$error" ]; then
error="$(jq -r '.data.error' 2>/dev/null <<< "$response")"
fi
Expand All @@ -182,7 +185,8 @@ function upload_file() {
fi

# Certain videos formats get returned without an extension in the URL.
local link="$(jq -r '.data.deletehash + ";" + .data.link' <<< "$response")"
local link
link="$(jq -r '.data.deletehash + ";" + .data.link' <<< "$response")"
if [[ "$link" == *'.' ]]; then
link="${link}mp4"
fi
Expand All @@ -202,7 +206,8 @@ function create_album() {
"${form[@]}")"

if [[ "$(jq -r '.success' <<< "$response")" == false ]]; then
local error="$(jq -r '.data.error.message' 2>/dev/null <<< "$response")"
local error
error="$(jq -r '.data.error.message' 2>/dev/null <<< "$response")"
if [ -z "$error" ]; then
error="$(jq -r '.data.error' 2>/dev/null <<< "$response")"
fi
Expand All @@ -216,8 +221,10 @@ function create_album() {

function print_urls() {
for f in "$@"; do
local url="$(cut -d';' -f2 <<< "$f")"
local src="$(cut -d';' -f3 <<< "$f")"
local url src
url="$(cut -d';' -f2 <<< "$f")"
src="$(cut -d';' -f3 <<< "$f")"

printf '%s: %s (%s)\n' "$program" "$url" "${src##*/}"
done
}
Expand Down

0 comments on commit c844518

Please sign in to comment.