Skip to content

Instantly share code, notes, and snippets.

@vitalizzare
Last active July 22, 2023 17:38
Show Gist options
  • Save vitalizzare/6e9c7ef9c459c0cf6484dc957e9c1507 to your computer and use it in GitHub Desktop.
Save vitalizzare/6e9c7ef9c459c0cf6484dc957e9c1507 to your computer and use it in GitHub Desktop.
#!/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