From 9c4f7e67b4829a5ba1fc2ef6cf255010e8805f4c Mon Sep 17 00:00:00 2001 From: yosh Date: Wed, 21 Jun 2023 17:08:12 -0500 Subject: [PATCH] using -n and -z for best practices --- albumsetup | 10 +++++----- discogarchive | 8 ++++---- n | 2 +- screenshot | 8 ++++---- stranslate | 4 ++-- twitch-notify | 2 +- xbps-clean | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/albumsetup b/albumsetup index 8aed09d..e926eab 100755 --- a/albumsetup +++ b/albumsetup @@ -106,12 +106,12 @@ trap 'clean' INT HUP QUIT EXIT [ "$EXT" = "opus" ] && acopy="-c:a copy" # copy audio codec if opus since output codec is opus # INDIVIDUAL SONG # -if [ "$SONG" ]; then +if [ -n "$SONG" ]; then grabinfo "$SONG" ffconv "$DEFAULT_PICTURE" "$SONG" "$OUTDIR/SONG ${ARTIST%%/*} - ${TITLE%%/*}.webm" # substitution mods are to not create directories # CONTINUOUS VIDEO OF WHOLE ALBUM # -elif [ "$FULLALBUM" ]; then +elif [ -n "$FULLALBUM" ]; then TOTALTIME=0 # keeping track of timestamps IFS="$NL" for f in $(fd -d 1 -e "$EXT"); do @@ -145,7 +145,7 @@ else [ ! -f "$PICTURE" ] && PICTURE="$(fd -e jpg -e png "^track$TRACKNUMBER")" [ ! -f "$PICTURE" ] && PICTURE="$DEFAULT_PICTURE" errecho "Converting $f" - [ ! "$NO_CONVERT" ] && ffconv "$PICTURE" "$f" "$OUTDIR/$TRACKNUMBER ${ARTIST%%/*} - ${TITLE%%/*}.webm" + [ -z "$NO_CONVERT" ] && ffconv "$PICTURE" "$f" "$OUTDIR/$TRACKNUMBER ${ARTIST%%/*} - ${TITLE%%/*}.webm" [ -f "$tmpimg" ] && rm -f "$tmpimg" done > "$OUTDIR/metadata.txt" [ ! -f "$OUTDIR/metadata.txt" ] && die "No files found!" @@ -157,7 +157,7 @@ else rm "$OUTDIR/metadata.txt.sorted" # Bandcamp check and info retrieval - if [ "$BANDCAMP" ]; then + if [ -n "$BANDCAMP" ]; then JSON="$(mktemp -t "ALBUMSETUP_JSON.XXXX")" curl -L -s -o - "$BANDCAMP" | pup 'script[type="application/ld+json"]' 'text{}' > "$JSON" albumartist="$(jq -r '.byArtist.name' < "$JSON")" @@ -169,7 +169,7 @@ else printf '%s - %s\n\n' "$albumartist" "$ALBUM" cat "$OUTDIR/metadata.txt" printf '\nReleased %s\nDOWNLOAD: %s\n\n' "$date" "$BANDCAMP" - [ "$desc" ] || [ "$creds" ] && printf '%s\n' 'Release notes:' + [ -n "$desc" ] || [ -n "$creds" ] && printf '%s\n' 'Release notes:' printf '%s\n\n%s' "$desc" "$creds" | sed -e 's/ "$OUTDIR/metadata2.txt" mv "$OUTDIR/metadata2.txt" "$OUTDIR/metadata.txt" diff --git a/discogarchive b/discogarchive index a584d19..d2d112d 100755 --- a/discogarchive +++ b/discogarchive @@ -96,11 +96,11 @@ done echo "$tmplog" > "$logdir/log" # formatting the description -if [ "${uncontained_albums}" ] || [ "${uncontained_tracks}" ]; then +if [ -n "${uncontained_albums}" ] || [ -n "${uncontained_tracks}" ]; then uncontained_albums="$NL
Uncontained Releases
$NL$uncontained_albums" - [ "$uncontained_tracks" ] && uncontained_tracks="$NL
SINGLES
$NL$uncontained_tracks" + [ -n "$uncontained_tracks" ] && uncontained_tracks="$NL
SINGLES
$NL$uncontained_tracks" fi -[ "$contained_tracks" ] && contained_tracks="$NL
SINGLES
$NL$contained_tracks" +[ -n "$contained_tracks" ] && contained_tracks="$NL
SINGLES
$NL$contained_tracks" contained_albums="$NL
Contained Releases
$NL$contained_albums" printf '%s%s%s%s%s%s' \ @@ -112,7 +112,7 @@ if [ ! "$no_download" ]; then printf '%s' 'CAT.ALL' > ./files/_rules.conf # artist img img="$(pup 'img.band-photo' 'attr{src}' < "$FILE")" - if [ "$img" ]; then + if [ -n "$img" ]; then ext="${img##*.}" curl -s -o ./files/artist."$ext" "${img%_*}_0.$ext" fi diff --git a/n b/n index 5518f1f..bf54daa 100755 --- a/n +++ b/n @@ -6,7 +6,7 @@ if [ "${NNNLVL:-0}" -ge 1 ]; then echo "don't nest nnn!" && exit fi -[ "${TMUX:-}" ] && exec nnn +[ -n "${TMUX:-}" ] && exec nnn vars="NNN_BATTHEME=Dracula NNN_BATSTYLE=full diff --git a/screenshot b/screenshot index fd2976e..5c57070 100755 --- a/screenshot +++ b/screenshot @@ -7,8 +7,8 @@ CATBOX_USERHASH="" # catbox userhash BASEIFS=$IFS clean() { - [ "$nsxiv_pid" ] && kill "$nsxiv_pid" - [ "$tmpfreeze" ] && rm -f "$tmpfreeze" + [ -n "$nsxiv_pid" ] && kill "$nsxiv_pid" + [ -f "$tmpfreeze" ] && rm -f "$tmpfreeze" rm -f "$tmpfp" } @@ -27,7 +27,7 @@ choose() { h1="$(md5sum "$tmpfp")" gimp -n "$tmpfp" h2="$(md5sum "$tmpfp")" - [ "$h1" != "$h2" ] && save # changed, save + [ -n "$h1" != "$h2" ] && save # changed, save ;; scan) zdata="$(zbarimg -1 "$tmpfp")" || zdata="error: scan failed with exit code $?" @@ -55,7 +55,7 @@ choose() { ss() { [ "$ssopts" = "-g" ] && ssopts="$(hacksaw -f "-i %i -g %g")" shotgun $ssopts "$tmpfp" - [ "$nsxiv_pid" ] && kill "$nsxiv_pid" && nsxiv_pid="" # unfreeze + [ -n "$nsxiv_pid" ] && kill "$nsxiv_pid" && nsxiv_pid="" # unfreeze xclip -selection clipboard -t image/png < "$tmpfp" # copy screenshot choose } diff --git a/stranslate b/stranslate index 54daa7a..b7be15f 100755 --- a/stranslate +++ b/stranslate @@ -47,7 +47,7 @@ while getopts :hi:f:t: OPT; do done shift $((OPTIND - 1)) -[ "$*" ] || set -- "$(cat /dev/stdin)" -[ "$*" ] || usage +[ -n "$*" ] || set -- "$(cat /dev/stdin)" +[ -n "$*" ] || usage curl -s "${INSTANCE}/api/translate?engine=${ENGINE}&from=${FLANG}&to=${TLANG}&text=$(jq -rn --arg x "$*" '$x|@uri')" | jq -r '."translated-text"' diff --git a/twitch-notify b/twitch-notify index bbd3027..908044f 100755 --- a/twitch-notify +++ b/twitch-notify @@ -28,7 +28,7 @@ MAX_TRIES=2 check() { trap 'innerclean '"$2" INT HUP TERM curl -s -o "$2" -L "https://twitch.tv/$1" - if [ "$(pup 'script[type="application/ld+json"]' < "$2")" ]; then + if [ -n "$(pup 'script[type="application/ld+json"]' < "$2")" ]; then if [ ! -f "$DIR/$1" ]; then touch "$DIR/$1" IMG="$(mktemp -t "twitch-notify-img.XXXX")" diff --git a/xbps-clean b/xbps-clean index 38b4ef8..678a66e 100755 --- a/xbps-clean +++ b/xbps-clean @@ -11,6 +11,6 @@ for x in /var/cache/xbps/*.xbps; do xbps-query "$(xbps-uhelper binpkgver "$x")" 1>/dev/null 2>&1 if [ $? -eq 2 ]; then echo "${x%.*}" - [ "$DEL" ] && rm "${x%.*}".* + [ -n "$DEL" ] && rm "${x%.*}".* fi done