diff --git a/bashbirds.sh b/bashbirds.sh index e791908..bc92d86 100755 --- a/bashbirds.sh +++ b/bashbirds.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION="v0.7" +VERSION="v0.9" red="\033[1;31m" greenbold="\033[1;32m" @@ -41,16 +41,26 @@ echo -e "${yellowbold}Bashbird${reset} $VERSION\n" req2() { - f_md="liste_oiseaux.md" - if [ -f "./$f_md" ]; then - rm "./$f_md" + option=$1 + + case $option in + m) ext=".md" ;; + w) ext=".html";old_index="_" ;; + esac + + f="liste_oiseaux$ext" + if [ -f "./$f" ]; then + rm "./$f" fi - read -p "Pause: " choice + + #read -p "Pause: " choice query2="SELECT * FROM liste;" result2=$(sqlite3 ./birds.db "$query2") #echo "$result2" - + + i=1 + index=() array=() while IFS='|' read -ra array; do @@ -62,20 +72,147 @@ req2() { fa="${array[5]}" ln="${array[6]}" [[ $aut != "" ]] && z="($aut)" || z="" + + if [ $ext = ".md" ]; then + echo "| $fr $z |" >>"$f" + echo "|--------------------------------------------------|" >>"$f" + echo "| $lat |" >> "$f" + echo "| $en |" >> "$f" + echo "| $or |" >> "$f" + echo "| $fa |" >> "$f" + echo "| $ln |" >> "$f" + echo "" >> "$f" + elif [ $ext = ".html" ]; then + firstletter="${fr:0:1}" + + if [ $firstletter != $old_index ]; then + index+=("$firstletter") + #bird+="$fr$aut$lat$en" + bird+="$fr$aut$lat$en" + else + bird+="$fr$aut$lat$en" + fi + bird+="$or$faOiseaux.net" + if [ $firstletter != $old_index ]; then + bird+="PLACEHOLDER" + else + bird+="" + fi + old_index="$firstletter" - echo "| $fr $z |" >>"$f_md" - echo "|--------------------------------------------------|" >>"$f_md" - echo "| $lat |" >> "$f_md" - echo "| $en |" >> "$f_md" - echo "| $or |" >> "$f_md" - echo "| $fa |" >> "$f_md" - echo "| $ln |" >> "$f_md" - echo "" >> "$f_md" + fi done <<< "$result2" + if [ $ext = ".html" ]; then + newArr=(); while IFS= read -r -d '' x; do newArr+=("$x"); done < <(printf "%s\0" "${index[@]}" | sort -uz) + + for val in ${!newArr[@]} + do + liens_index+="${newArr[$val]} | " + done + liens_index="${liens_index:0:-3}" + z=${bird//PLACEHOLDER/$liens_index} + bird="$z" + + html + fi + exit 0 } + +html() { +cat > liste_oiseaux.html << EOF + + + + + +Liste oiseaux d'Europe... + + + + + + + + + + + +

+ + +
$liens_index
+$bird +
Liste des oiseaux d'Europe.
+ + + +EOF + +} req1() { echo -e "${bold}Recherche: <$1>${reset}" @@ -85,7 +222,6 @@ req1() { request=""; fi - #query1="SELECT * FROM liste WHERE Francais LIKE \"%$1%\" OR Autres LIKE \"%$1%\" OR Latin LIKE \"%$1%\""; query1="SELECT * FROM liste WHERE Francais LIKE \"%$request%\" OR Autres LIKE \"%$request%\" OR Latin LIKE \"%$request%\""; result1=$(sqlite3 ./birds.db "$query1") @@ -209,11 +345,10 @@ Help() { echo "-w Export html." } -while getopts "b:hm" options; do +while getopts "b:hmw" options; do case "${options}" in - # b) Bird="${OPTARG}" ;; b) req1 "${OPTARG}" ;; - m) req2 ;; + m|w) req2 "${options}" ;; v) printf "%s\n" "$VERSION" ; exit 0 ;; h|*) Help ; exit 2 ;; esac