using -n and -z for best practices

This commit is contained in:
yosh 2023-06-21 17:08:12 -05:00
parent 2ecadef2a9
commit 9c4f7e67b4
7 changed files with 18 additions and 18 deletions

View File

@ -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/<//g'
} > "$OUTDIR/metadata2.txt"
mv "$OUTDIR/metadata2.txt" "$OUTDIR/metadata.txt"

View File

@ -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<br><div><b>Uncontained Releases</b></div>$NL$uncontained_albums"
[ "$uncontained_tracks" ] && uncontained_tracks="$NL<br><div><u>SINGLES</u></div>$NL$uncontained_tracks"
[ -n "$uncontained_tracks" ] && uncontained_tracks="$NL<br><div><u>SINGLES</u></div>$NL$uncontained_tracks"
fi
[ "$contained_tracks" ] && contained_tracks="$NL<br><div><u>SINGLES</u></div>$NL$contained_tracks"
[ -n "$contained_tracks" ] && contained_tracks="$NL<br><div><u>SINGLES</u></div>$NL$contained_tracks"
contained_albums="$NL<br><div><b>Contained Releases</b></div>$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

2
n
View File

@ -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

View File

@ -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
}

View File

@ -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"'

View File

@ -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")"

View File

@ -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