20-08-2024

This commit is contained in:
2024-08-20 09:29:37 +02:00
parent faf27258ec
commit ebc9987cab
3 changed files with 67 additions and 64 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.DS_Store

View File

@@ -47,13 +47,13 @@ req2() {
read -p "Pause: " choice read -p "Pause: " choice
query2="SELECT * FROM liste;" query2="SELECT * FROM liste;"
result2=$(sqlite3 ./birds_plus.db "$query2") result2=$(sqlite3 ./birds.db "$query2")
#echo "$result2" #echo "$result2"
array=() array=()
while IFS='|' read -ra array; while IFS='|' read -ra array;
do do
fr="${array[0]}" fr="${array[0]}"
aut="${array[1]}" aut="${array[1]}"
lat="${array[2]}" lat="${array[2]}"
en="${array[3]}" en="${array[3]}"
@@ -77,50 +77,73 @@ req2() {
} }
req1() { req1() {
query1="SELECT * FROM liste WHERE francais LIKE \"%$1%\""; echo -e "${bold}Recherche: <$1>${reset}"
result1=$(sqlite3 ./birds_plus.db "$query1")
#echo "$result1"
array2=() request="$1"
keywords=() if [[ "${request,,}" == "all" ]]; then
cmpt=1 request="";
while IFS='|' read -ra array2; fi
do
fr2="${array2[0]}"
aut2="${array2[1]}"
lat2="${array2[2]}"
en2="${array2[3]}"
or2="${array2[4]}"
fa2="${array2[5]}"
lnk2="${array2[6]}"
tag2="$fr2,$lat2,$en2" #query1="SELECT * FROM liste WHERE Francais LIKE \"%$1%\" OR Autres LIKE \"%$1%\" OR Latin LIKE \"%$1%\"";
if [ -n "$or2" ]; then query1="SELECT * FROM liste WHERE Francais LIKE \"%$request%\" OR Autres LIKE \"%$request%\" OR Latin LIKE \"%$request%\"";
tag2+=",$or2" result1=$(sqlite3 ./birds.db "$query1")
fi
if [ -n "$fa2" ]; then
tag2+=",$fa2"
fi
#echo "${#fr2} ; ${#aut2} ; ${#lat2} ; ${#en2} ; ${#or2} ; ${#fa2} ; ${#lnk2}"
echo if [ -n "$result1" ]; then
printf "\e[1m| %-3s | %-25s | %-25s | %-25s | %-20s | %-20s \e[0m\n" "$cmpt" "$fr2" "$lat2" "$en2" "$or2" "$fa2" array2=()
printf "| %-3s | %-55s \n" "$cmpt" "$lnk2" keywords=()
printf "\e[0;34m| %-3s | %-55s \e[0m\n" "$cmpt" "$tag2" cmpt=1
keywords+=("$tag2") while IFS='|' read -ra array2;
cmpt=$((cmpt+1)) do
done <<< "$result1" fr2="${array2[0]}"
aut2="${array2[1]}"
lat2="${array2[2]}"
en2="${array2[3]}"
or2="${array2[4]}"
fa2="${array2[5]}"
lnk2="${array2[6]}"
choose=$(echo -e "\nChoose a number to get keywords in your clipboard: ") tag2="$fr2"
read -e -p "$choose" choice if [ -n "$aut2" ]; then
tag2+=",$aut2"
fi
tag2+=",$lat2,$en2"
if [ -n "$or2" ]; then
tag2+=",$or2"
fi
if [ -n "$fa2" ]; then
tag2+=",$fa2"
fi
#echo "${#fr2} ; ${#lat2} ; ${#en2} ; ${#or2} ; ${#fa2} ; ${#lnk2} ; ${#aut2} "
if [ "$choice" -ge "1" ] && [ "$choice" -le "$((cmpt-1))" ]; then echo
if [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v xsel)" ]; then printf "\e[1m| %-3s | %-25s | %-20s | %-20s | %-18s | %-15s | %-20s \e[0m\n" "$cmpt" "$fr2" "$lat2" "$en2" "$or2" "$fa2" "$aut2"
xsel -b <<< "${keywords[$((choice-1))]}" printf "| %-3s | %-55s \n" "$cmpt" "$lnk2"
elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v pbcopy)" ]; then printf "\e[0;34m| %-3s | %-55s \e[0m\n" "$cmpt" "$tag2"
pbcopy <<< "${keywords[$((choice-1))]}" keywords+=("$tag2")
cmpt=$((cmpt+1))
done <<< "$result1"
choose=$(echo -e "\nChoose a number to get keywords in your clipboard (<q> to quit): ")
read -e -p "$choose" choice
re='^[0-9]+$'
if [[ $choice == "q" ]] || [[ $choice == "Q" ]]; then
exit 0
elif ! [[ $choice =~ $re ]] ; then
echo -e "${red}Wrong index !${reset}"
else
if [ "$choice" -ge 1 ] && [ "$choice" -le "$((cmpt-1))" ]; then
if [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v xsel)" ]; then
xsel -b <<< "${keywords[$((choice-1))]}"
elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v pbcopy)" ]; then
pbcopy <<< "${keywords[$((choice-1))]}"
fi
else echo -e "${red}Wrong index !${reset}"
fi
fi fi
else echo "Wrong index !"
else
echo -e "\n ${red}No results found!"
fi fi
} }
@@ -167,17 +190,7 @@ if [[ "$VERSION" != "$LatestRelease" ]] ; then
fi fi
if [ -f ./birds_plus.db ]; then if [ ! -f ./birds.db ]; then
#echo "$result"
#req2
echo
#req1 "$1"
else
echo -e "${red}No database found !${reset}" echo -e "${red}No database found !${reset}"
exit 1 exit 1
fi fi
@@ -188,7 +201,7 @@ Help() {
echo "Example: birds.sh -b buse" echo "Example: birds.sh -b buse"
echo echo
echo "Options:" echo "Options:"
echo "-b -b bird, -b all." echo "-b -b <bird>, -b all."
echo "-h Print this Help." echo "-h Print this Help."
echo "-m Export markdown." echo "-m Export markdown."
echo "-v Prints current version." echo "-v Prints current version."
@@ -205,14 +218,3 @@ while getopts "b:hm" options; do
esac esac
done done
shift "$((OPTIND-1))" shift "$((OPTIND-1))"
: <<'END_COMMENT'
echo "bird: $Bird"
read -p "Pause: " choice
if [ $Bird == "all" ]; then
req1
elif [ -n $Bird ]; then
req1 "$Bird"
fi
END_COMMENT

BIN
birds.db

Binary file not shown.