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