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,7 +47,7 @@ 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=()
@@ -77,10 +77,18 @@ 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"
request="$1"
if [[ "${request,,}" == "all" ]]; then
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")
if [ -n "$result1" ]; then
array2=() array2=()
keywords=() keywords=()
cmpt=1 cmpt=1
@@ -94,33 +102,48 @@ req1() {
fa2="${array2[5]}" fa2="${array2[5]}"
lnk2="${array2[6]}" lnk2="${array2[6]}"
tag2="$fr2,$lat2,$en2" tag2="$fr2"
if [ -n "$aut2" ]; then
tag2+=",$aut2"
fi
tag2+=",$lat2,$en2"
if [ -n "$or2" ]; then if [ -n "$or2" ]; then
tag2+=",$or2" tag2+=",$or2"
fi fi
if [ -n "$fa2" ]; then if [ -n "$fa2" ]; then
tag2+=",$fa2" tag2+=",$fa2"
fi fi
#echo "${#fr2} ; ${#aut2} ; ${#lat2} ; ${#en2} ; ${#or2} ; ${#fa2} ; ${#lnk2}" #echo "${#fr2} ; ${#lat2} ; ${#en2} ; ${#or2} ; ${#fa2} ; ${#lnk2} ; ${#aut2} "
echo echo
printf "\e[1m| %-3s | %-25s | %-25s | %-25s | %-20s | %-20s \e[0m\n" "$cmpt" "$fr2" "$lat2" "$en2" "$or2" "$fa2" printf "\e[1m| %-3s | %-25s | %-20s | %-20s | %-18s | %-15s | %-20s \e[0m\n" "$cmpt" "$fr2" "$lat2" "$en2" "$or2" "$fa2" "$aut2"
printf "| %-3s | %-55s \n" "$cmpt" "$lnk2" printf "| %-3s | %-55s \n" "$cmpt" "$lnk2"
printf "\e[0;34m| %-3s | %-55s \e[0m\n" "$cmpt" "$tag2" printf "\e[0;34m| %-3s | %-55s \e[0m\n" "$cmpt" "$tag2"
keywords+=("$tag2") keywords+=("$tag2")
cmpt=$((cmpt+1)) cmpt=$((cmpt+1))
done <<< "$result1" done <<< "$result1"
choose=$(echo -e "\nChoose a number to get keywords in your clipboard: ") choose=$(echo -e "\nChoose a number to get keywords in your clipboard (<q> to quit): ")
read -e -p "$choose" choice read -e -p "$choose" choice
if [ "$choice" -ge "1" ] && [ "$choice" -le "$((cmpt-1))" ]; then 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 if [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v xsel)" ]; then
xsel -b <<< "${keywords[$((choice-1))]}" xsel -b <<< "${keywords[$((choice-1))]}"
elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v pbcopy)" ]; then elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v pbcopy)" ]; then
pbcopy <<< "${keywords[$((choice-1))]}" pbcopy <<< "${keywords[$((choice-1))]}"
fi fi
else echo "Wrong index !" else echo -e "${red}Wrong index !${reset}"
fi
fi
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.