Skip to content

Commit 28cc28a

Browse files
authored
feat: add --about flag to cli-tips (#1)
Suggested-by: rendick <[email protected]>
1 parent dee78b5 commit 28cc28a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ LANG=de cli-tips
8080
# Output: Verwenden Sie 'uniq', um doppelte Zeilen aus einer Datei zu entfernen
8181
```
8282

83+
### Use the `--about` Flag
84+
85+
To display a random tip containing a specific keyword, use the `--about` option:
86+
87+
```bash
88+
cli-tips --about=git
89+
# Output: Use 'git status' to check the status of your git repository
90+
```
91+
92+
If no tips contain the specified keyword, no tip will be output.
93+
8394
### Available Languages
8495

8596
Here is a list of all available languages:

cli-tips.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -81,6 +87,22 @@ fi
8187
# Read tips from the file into an array
8288
mapfile -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
85107
tip_index=$((RANDOM % ${#tips[@]}))
86108

0 commit comments

Comments
 (0)