From b58bf60fe5bc511ddd5dab8e361f1121735d83b8 Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Wed, 3 Jan 2024 09:15:48 +0100 Subject: [PATCH] shellcheck --- keywords2insta.sh | 55 +++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/keywords2insta.sh b/keywords2insta.sh index 80ccb0b..e2235fe 100755 --- a/keywords2insta.sh +++ b/keywords2insta.sh @@ -46,24 +46,23 @@ map_size="450x450" prefix=${map_size%%x*} # find x position in map_size string x=${#prefix} gm_width=${map_size:0:$x} -echo $gm_width -long_path=`pwd`"/"`basename "$0"` # /Users/bruno/Documents/Scripts/kymsu2/keywords2insta.sh +#long_path=$(pwd)"/"$(basename "$0") # /Users/bruno/Documents/Scripts/kymsu2/keywords2insta.sh # long: /Users/bruno/Documents/GitHub/GooFuzz/keywords2insta.sh -#long_path=$(realpath "$0") # vide dir=$(dirname "$0") # /Users/bruno/Documents/Scripts/keywords2insta dotenv () { set -a - [ -f .env ] && . .env || echo -e "${red}\nNo .env file found ! Googlemaps reverse geocode not working.${reset}" + # shellcheck disable=SC1091 + [ -f "$HOME/.env" ] && . "$HOME/.env" || echo -e "${red}\nNo .env file found ! Googlemaps reverse geocode not working.${reset}" set +a } dotenv trim () { - read -rd '' $1 <<<"${!1}" + read -rd '' "$1" <<<"${!1}" } alpha_name= @@ -73,7 +72,7 @@ alpha () { #declare -A ilce=( ['ILCE-7M3']="Alpha 7 III" ['ILCE-7M4']="α7 IV" ['ILCE-7MRM5']="α7R V" ['ILCE-7SM3']="Alpha 7S III" ['ILCE-7RM4']="α7R IV" ['ILCE-7RM3']="α7R III" ['ILCE-7C']="Alpha 7C" ) declare -A ilce - if [ -f $dir/sony.csv ]; then + if [ -f "$dir"/sony.csv ]; then #echo "Loading Sony APNs..." @@ -82,7 +81,7 @@ alpha () { key="${array[0]}" value="${array[1]}" ilce["$key"]="$value" - done < $dir/sony.csv + done < "$dir"/sony.csv fi @@ -251,7 +250,7 @@ en=() array2=() declare -A dico -if [ -f $dir/keywords.csv ]; then +if [ -f "$dir"/keywords.csv ]; then echo "Loading keyword dictionary..." @@ -259,7 +258,7 @@ if [ -f $dir/keywords.csv ]; then do fr+=("${array2[0]}") en+=("${array2[1]}") - done < $dir/keywords.csv + done < "$dir"/keywords.csv j=0 for i in "${fr[@]}" @@ -331,16 +330,18 @@ fi # Display thumb image -if [ "$(echo $__CFBundleIdentifier | grep iterm2)" ]; then +if [ "$(echo "$__CFBundleIdentifier" | grep iterm2)" ]; then tmp_path=/tmp/k2i [ -d $tmp_path ] && rm -rf $tmp_path mkdir $tmp_path - tempfoo=`basename "$file"` - magick "$file" -quality 50 -resize 600x600\> $tmp_path/thumb_$tempfoo + #tempfoo=`basename "$file"` + tempfoo=$(basename "$file") + magick "$file" -quality 50 -resize 600x600\> $tmp_path/thumb_"$tempfoo" if [ -f "$tmp_path/thumb_$tempfoo" ]; then - [ $width -gt $height ] && w_thumb=600 || w_thumb=$(echo "600/3*2" | bc) - printf "\n\t\033]1337;File=;width=$w_thumb px;inline=1:`cat $tmp_path/thumb_$tempfoo | base64`\a\n" + [ "$width" -gt "$height" ] && w_thumb=600 || w_thumb=$(echo "600/3*2" | bc) + #printf "\n\t\033]1337;File=;width=$w_thumb px;inline=1:`cat $tmp_path/thumb_$tempfoo | base64`\a\n" + printf "\n\t\033]1337;File=;width=$w_thumb px;inline=1:$(cat $tmp_path/thumb_$tempfoo | base64)\a\n" fi fi @@ -429,16 +430,16 @@ if [[ -n $iso ]] && [[ -n $speed ]] && [[ -n $aperture ]]; then l="$lens" fi # width > height && w=2400 || w=1600 - if [ $width -gt $height ]; then + if [ "$width" -gt "$height" ]; then wi=2400 he=1600 - [ $width -ne $wi ] && printf " %-11s %-35b \n" "Width:" "${red}${width}${reset}" || printf " %-11s %-35s \n" "Width:" "${width}" - [ $height -ne $he ] && printf " %-11s %-35b \n" "Height:" "${red}${height}${reset}" || printf " %-11s %-35s \n" "Height:" "${height}" - elif [ $height -gt $width ]; then + [ "$width" -ne "$wi" ] && printf " %-11s %-35b \n" "Width:" "${red}${width}${reset}" || printf " %-11s %-35s \n" "Width:" "${width}" + [ "$height" -ne "$he" ] && printf " %-11s %-35b \n" "Height:" "${red}${height}${reset}" || printf " %-11s %-35s \n" "Height:" "${height}" + elif [ "$height" -gt "$width" ]; then wi=1600 he=2400 - [ $width -ne $wi ] && printf " %-11s %-35b \n" "Width:" "${red}${width}${reset}" || printf " %-11s %-35s \n" "Width:" "${width}" - [ $height -ne $he ] && printf " %-11s %-3b \n" "Height:" "${red}${height}${reset}" || printf " %-11s %-35s \n" "Height:" "${height}" + [ "$width" -ne "$wi" ] && printf " %-11s %-35b \n" "Width:" "${red}${width}${reset}" || printf " %-11s %-35s \n" "Width:" "${width}" + [ "$height" -ne "$he" ] && printf " %-11s %-3b \n" "Height:" "${red}${height}${reset}" || printf " %-11s %-35s \n" "Height:" "${height}" fi #printf " %-11s %-35s \n" "Width:" "${width}" #printf " %-11s %-35s \n" "Height:" "${height}" @@ -480,13 +481,15 @@ if [[ -n $iso ]] && [[ -n $speed ]] && [[ -n $aperture ]]; then gm_path=/tmp/k2i/gm.png curl -s "$url" --output $gm_path if [ -f "$gm_path" ]; then - printf "\n\t\033]1337;File=;width=$((gm_width * 2)) px;inline=1:`cat $gm_path | base64`\a\n" + #printf "\n\t\033]1337;File=;width=$((gm_width * 2)) px;inline=1:`cat $gm_path | base64`\a\n" + printf "\n\t\033]1337;File=;width=$((gm_width * 2)) px;inline=1:$(cat $gm_path | base64)\a\n" fi fi fi fi + printf " %-11s %-35s \n" "Software:" "${software}" printf " %-11s %-35s \n" "Comment:" "${comment}" printf " %-11s %-35s \n" "Artist:" "${artist}" printf " %-11s %-35s \n" "Copyright:" "${copyright}" @@ -502,7 +505,7 @@ if [ $opt_gps = true ]; then echo -e "${red}GPS data available !${reset}" d=$(echo -e "Do you want to ${bold}erase GPS data${reset} ? (k)eep or (e)rase ") - read -p "$d" choice + read -r -p "$d" choice if [ "$choice" == "e" ] || [ "$choice" == "E" ]; then echo "Erasing GPS data..." @@ -519,7 +522,7 @@ fi # copyright if [ $opt_copyright = false ]; then b=$(echo -e "Do you want to ${bold}erase Artist and Copyright data${reset} ? (k)eep or (e)rase ") - read -p "$b" choice + read -r -p "$b" choice if [ "$choice" == "e" ] || [ "$choice" == "E" ]; then echo "Erasing Artist and Copyright data..." @@ -540,7 +543,7 @@ if [ -z "$k" ]; then fi -IFS="," read -a key <<< "$k" +IFS="," read -r -a key <<< "$k" for i in "${key[@]}" @@ -877,7 +880,7 @@ if [ "$insta" = true ]; then echo -e "\n${bold}The Instagram's tags are available in your clipboard !${reset}" echo "$keywords_insta" - [ "$flickr" = true ] || [ "$ccpx" = true ] && echo -e "\nPress to get the Flickr's or the 500px's tags..." && read -p "" + [ "$flickr" = true ] || [ "$ccpx" = true ] && echo -e "\nPress to get the Flickr's or the 500px's tags..." && read -r -p "" fi @@ -891,7 +894,7 @@ if [ "$flickr" = true ]; then [ "$insta" = true ] && echo -e "\n${bold}Here the Flickr's tags too !${reset}" || echo -e "\n${bold}The Flickr's tags are available in your clipboard !${reset}" echo "$keywords_flickr" - "$ccpx" = true ] && echo -e "\nPress to get the 500px's tags..." && read -p "" + [ "$ccpx" = true ] && echo -e "\nPress to get the 500px's tags..." && read -r -p "" fi if [ "$ccpx" = true ]; then