Last active
July 22, 2023 17:38
-
-
Save vitalizzare/6e9c7ef9c459c0cf6484dc957e9c1507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# pydoc_grep <keyword> | |
# Grep for the keyword through the pydoc's topics | |
keyword="${1:?Give me a keyword to look for as a first parameter}" | |
python -m pydoc 'topics' | awk '/^[A-Z ]+$/ {for (i=1; i<=NF; i++) print $i}' | { | |
unset found | |
while read topic; do | |
python -m pydoc "$topic" | grep --ignore-case "$keyword" > /dev/null | |
[ $? -eq 0 ] && { | |
# print the topic name if it contains the keyword | |
echo $topic | |
found='yes' | |
} | |
done | |
# correct exit code | |
[ "$found" ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment