@@ -33,6 +33,7 @@ show_help() {
3333 echo -e " \e[1mOptions:\e[0m"
3434 echo -e " \e[1;34m-h, --help\e[0m Show this help message and exit"
3535 echo -e " \e[1;34m-l, --lang, --language\e[0m Specify the language for tips"
36+ echo -e " \e[1;34m--about\e[0m Specify a keyword to filter tips"
3637 echo
3738 echo -e " \e[1mAvailable Languages:\e[0m"
3839 printf " "
@@ -44,6 +45,7 @@ show_help() {
4445 echo -e " \e[1mExamples:\e[0m"
4546 echo -e " $( basename " $0 " ) \e[1;34m--language\e[0m en"
4647 echo -e " $( basename " $0 " ) \e[1;34m--language\e[0m es"
48+ echo -e " $( basename " $0 " ) \e[1;34m--about\e[0m git"
4749 echo
4850 echo
4951 echo -e " \e[1mGitHub:\e[0m \e[0;30mhttps://github.com/cli-stuff/cli-tips\e[0m"
@@ -59,6 +61,10 @@ while [[ "$#" -gt 0 ]]; do
5961 --language=* | --lang=* )
6062 LANGUAGE=" ${1#* =} "
6163 ;;
64+ --about)
65+ KEYWORD=" $2 "
66+ shift
67+ ;;
6268 -h | --help)
6369 show_help
6470 exit 0
8187# Read tips from the file into an array
8288mapfile -t tips < " $localized_file "
8389
90+ # Filter tips based on the specified keyword
91+ if [ -n " $KEYWORD " ]; then
92+ filtered_tips=()
93+ for tip in " ${tips[@]} " ; do
94+ if [[ " $tip " == * " $KEYWORD " * ]]; then
95+ filtered_tips+=(" $tip " )
96+ fi
97+ done
98+ tips=(" ${filtered_tips[@]} " )
99+ fi
100+
101+ # If there are no matching tips, exit
102+ if [ ${# tips[@]} -eq 0 ]; then
103+ exit 0
104+ fi
105+
84106# Generate random index
85107tip_index=$(( RANDOM % ${# tips[@]} ))
86108
0 commit comments