Add some help
-showHelp()
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
red="\033[1;31m"
|
red="\033[1;31m"
|
||||||
|
greenbold="\033[1;32m"
|
||||||
|
green="\033[0;32m"
|
||||||
|
yellow="\033[0;33m"
|
||||||
bold="\033[1m"
|
bold="\033[1m"
|
||||||
|
bold_under="\033[1;4m"
|
||||||
|
underline="\033[4m"
|
||||||
reset="\033[0m"
|
reset="\033[0m"
|
||||||
|
|
||||||
|
|
||||||
@@ -23,10 +28,84 @@ opt_nature=false
|
|||||||
opt_wildlife=false
|
opt_wildlife=false
|
||||||
opt_all=true
|
opt_all=true
|
||||||
|
|
||||||
|
showHelp() {
|
||||||
|
echo -e "${greenbold}keywords2insta${reset} v0.5"
|
||||||
|
echo -e "Bruno <bruno<clicclac.info>"
|
||||||
|
echo -e "Read exif and keywords from an image file, and copy them to the clipboard, "
|
||||||
|
echo -e " ready for Instagram and Flickr."
|
||||||
|
echo
|
||||||
|
echo -e "${yellow}USAGE:${reset}"
|
||||||
|
echo -e "${green}keyword2insta [-Options...] -f <file>${reset}"
|
||||||
|
echo -e "If no option is chosen, all tags are added (default). "
|
||||||
|
echo -e "Keywords taken from exifs are automatically added."
|
||||||
|
echo -e "The images files are not modified."
|
||||||
|
echo
|
||||||
|
echo -e "${yellow}OPTIONS:${reset}"
|
||||||
|
echo -e " ${green}-f${reset}, ${green}--file <file>${reset} Image file"
|
||||||
|
echo -e " ${green}-l${reset}, ${green}--lens${reset} Add lens exif"
|
||||||
|
echo -e " ${green}-m${reset}, ${green}--model${reset} Add APN model exif"
|
||||||
|
echo -e " ${green}-n${reset}, ${green}--nature${reset} Add nature related keywords"
|
||||||
|
echo -e " ${green}-r${reset}, ${green}--region${reset} Add region related keywords"
|
||||||
|
echo -e " ${green}-t${reset} <keyword>${reset} Add some additionnals keywords"
|
||||||
|
echo -e " ${green}-w${reset}, ${green}--wildlife${reset} Add wildlife related keywords"
|
||||||
|
echo -e " ${green}-h${reset}, ${green}--help${reset} Display this help"
|
||||||
|
echo
|
||||||
|
echo -e "${yellow}REQUIEREMENTS:${reset}"
|
||||||
|
echo -e " -${underline}exiftool${reset} for extract exifs ${bold}(requis)${reset}"
|
||||||
|
echo -e " brew install exiftool"
|
||||||
|
echo -e " -${underline}iconv${reset} for suppress accent (optional"
|
||||||
|
echo -e " brew install iconv"
|
||||||
|
echo -e " -${underline}gawk${reset} for suppress doubles (optional)"
|
||||||
|
echo -e " brew install gawk"
|
||||||
|
echo
|
||||||
|
echo -e "${yellow}EXAMPLES:${reset}"
|
||||||
|
echo -e " keyword2insta -f image.jpg"
|
||||||
|
echo -e " keyword2insta -lm -f image.jpg"
|
||||||
|
echo -e " keyword2insta --lens --model --file image.jpg"
|
||||||
|
echo -e " keyword2insta -lm -t deer mammal animal -f deer.jpg"
|
||||||
|
echo
|
||||||
|
echo -e "${yellow}EXIT CODES:${reset}"
|
||||||
|
echo -e " 0: Success !"
|
||||||
|
echo -e " 1: Exiftool could not be found."
|
||||||
|
echo -e " 2: No image file."
|
||||||
|
echo -e " 3: Unknown long option."
|
||||||
|
echo -e " 4: Unknown short option."
|
||||||
|
echo -e " 5: No Keywords found in image file."
|
||||||
|
}
|
||||||
|
|
||||||
|
# https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options
|
||||||
|
# le 1er : de $optspec supprime le message d'erreur
|
||||||
unset -v tags
|
unset -v tags
|
||||||
while getopts "wnrf:t:ml" opt
|
#OPTIND=1
|
||||||
|
optspec=":wnrf:t:mlh-:"
|
||||||
|
while getopts "$optspec" opt
|
||||||
do
|
do
|
||||||
case $opt in
|
case $opt in
|
||||||
|
-) case "${OPTARG}" in
|
||||||
|
help) showHelp; exit;;
|
||||||
|
wildlife) opt_wildlife=true;;
|
||||||
|
nature) opt_nature=true;;
|
||||||
|
region) opt_region=true;;
|
||||||
|
# "$@" --lens -t mammifère foret animal --file /Users/bruno/Pictures/Export/2022/Juillet/2022-07-01_Chevrette_3462.jpg
|
||||||
|
# "${OPTARG}" file
|
||||||
|
# "${OPTIND}" 7
|
||||||
|
file)
|
||||||
|
file="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
|
||||||
|
;;
|
||||||
|
file=*)
|
||||||
|
file=${OPTARG#*=}
|
||||||
|
#opt=${OPTARG%=$file}
|
||||||
|
opt="$(printf "%s\n" "${OPTARG}" | cut -d'=' -f1 )" ; file="$(printf "%s\n" "${OPTARG}" | cut -d'=' -f2-)"
|
||||||
|
;;
|
||||||
|
model) opt_model=true;;
|
||||||
|
lens) opt_lens=true;;
|
||||||
|
*)
|
||||||
|
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" = ":" ]; then
|
||||||
|
echo "Unknown option --${OPTARG}" >&2
|
||||||
|
fi
|
||||||
|
exit 3
|
||||||
|
;;
|
||||||
|
esac;;
|
||||||
w) opt_wildlife=true;;
|
w) opt_wildlife=true;;
|
||||||
n) opt_nature=true;;
|
n) opt_nature=true;;
|
||||||
r) opt_region=true;;
|
r) opt_region=true;;
|
||||||
@@ -39,12 +118,19 @@ do
|
|||||||
;;
|
;;
|
||||||
m) opt_model=true;;
|
m) opt_model=true;;
|
||||||
l) opt_lens=true;;
|
l) opt_lens=true;;
|
||||||
|
h)
|
||||||
|
showHelp
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknow option '-$opt'" >&2
|
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
|
||||||
exit -1;;
|
echo "Non-option argument: '-${OPTARG}'" >&2
|
||||||
|
fi
|
||||||
|
exit 4
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
#shift $((OPTIND-1))
|
||||||
|
|
||||||
if [ $opt_lens = true ] || [ $opt_model = true ] || [ $opt_region = true ] || [ $opt_nature = true ] || [ $opt_wildlife = true ]; then
|
if [ $opt_lens = true ] || [ $opt_model = true ] || [ $opt_region = true ] || [ $opt_nature = true ] || [ $opt_wildlife = true ]; then
|
||||||
opt_all=false
|
opt_all=false
|
||||||
@@ -69,7 +155,7 @@ if ! command -v exiftool &> /dev/null; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ ! -f "$file" ] && echo -e "${bold}${red}No input file !${reset}" && exit 1
|
[ ! -f "$file" ] && echo -e "${bold}${red}No input file !${reset}" && exit 2
|
||||||
|
|
||||||
# dico français / anglais
|
# dico français / anglais
|
||||||
|
|
||||||
@@ -109,7 +195,7 @@ k=$(echo "$exif" | sed -n '/^Keywords/p' | awk -F":" '{print $2}' | sed 's/^ *//
|
|||||||
if [ -z "$k" ]; then
|
if [ -z "$k" ]; then
|
||||||
echo -e "${bold}${red}No Keywords found !${reset}"
|
echo -e "${bold}${red}No Keywords found !${reset}"
|
||||||
echo "Quit."
|
echo "Quit."
|
||||||
exit 1
|
exit 5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user