20-08-2024
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.DS_Store
|
||||||
130
bashbirds.sh
130
bashbirds.sh
@@ -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"
|
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")
|
||||||
|
|
||||||
array2=()
|
if [ -n "$result1" ]; then
|
||||||
keywords=()
|
array2=()
|
||||||
cmpt=1
|
keywords=()
|
||||||
while IFS='|' read -ra array2;
|
cmpt=1
|
||||||
do
|
while IFS='|' read -ra array2;
|
||||||
fr2="${array2[0]}"
|
do
|
||||||
aut2="${array2[1]}"
|
fr2="${array2[0]}"
|
||||||
lat2="${array2[2]}"
|
aut2="${array2[1]}"
|
||||||
en2="${array2[3]}"
|
lat2="${array2[2]}"
|
||||||
or2="${array2[4]}"
|
en2="${array2[3]}"
|
||||||
fa2="${array2[5]}"
|
or2="${array2[4]}"
|
||||||
lnk2="${array2[6]}"
|
fa2="${array2[5]}"
|
||||||
|
lnk2="${array2[6]}"
|
||||||
|
|
||||||
tag2="$fr2,$lat2,$en2"
|
tag2="$fr2"
|
||||||
if [ -n "$or2" ]; then
|
if [ -n "$aut2" ]; then
|
||||||
tag2+=",$or2"
|
tag2+=",$aut2"
|
||||||
fi
|
fi
|
||||||
if [ -n "$fa2" ]; then
|
tag2+=",$lat2,$en2"
|
||||||
tag2+=",$fa2"
|
if [ -n "$or2" ]; then
|
||||||
fi
|
tag2+=",$or2"
|
||||||
#echo "${#fr2} ; ${#aut2} ; ${#lat2} ; ${#en2} ; ${#or2} ; ${#fa2} ; ${#lnk2}"
|
fi
|
||||||
|
if [ -n "$fa2" ]; then
|
||||||
|
tag2+=",$fa2"
|
||||||
|
fi
|
||||||
|
#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 [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v xsel)" ]; then
|
if [[ $choice == "q" ]] || [[ $choice == "Q" ]]; then
|
||||||
xsel -b <<< "${keywords[$((choice-1))]}"
|
exit 0
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v pbcopy)" ]; then
|
elif ! [[ $choice =~ $re ]] ; then
|
||||||
pbcopy <<< "${keywords[$((choice-1))]}"
|
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
|
|
||||||
Reference in New Issue
Block a user