2 changed files with 44 additions and 0 deletions
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash |
||||
|
||||
# CLI for https://command-not-found.com. |
||||
|
||||
trim() { |
||||
tr -d '\n' |
||||
} |
||||
|
||||
die() { |
||||
echo "$*" >&2 |
||||
exit 1 |
||||
} |
||||
|
||||
xpath() { |
||||
xmllint --html --xpath "$1" - 2>&- |
||||
} |
||||
|
||||
if [ -z "$1" ]; then |
||||
die "USAGE: $(basename "$0") COMMAND_NAME" |
||||
fi |
||||
|
||||
CNF_PAGE=$(curl -sq -L "command-not-found.com/$1") |
||||
|
||||
CMD_NAME=$(xpath '//*[contains(@class, "row-command-info")]/div/h2/text()' <<<"$CNF_PAGE" | trim) |
||||
|
||||
[ -z "$CMD_NAME" ] && die "Command '$1' not found." |
||||
|
||||
CMD_DESCRIPTION=$(xpath '(//*[contains(@class, "row-command-info")]/div/p)[1]/text()' <<<"$CNF_PAGE" \ |
||||
| trim | sed -E 's/(.)\.(.)/\1. \2/g' | fmt -s -w 60) |
||||
|
||||
OS_LIST=$(xpath '//*[contains(@class, "card-body")]/dl/div/dt/text()' <<<"$CNF_PAGE" \ |
||||
| sed -E '/^$/d; s/^[[:space:]]+//') |
||||
|
||||
INSTALL_CMDS=$(xpath '//div[@class="card-body"]/dl/div/dd/code' <<<"$CNF_PAGE" \ |
||||
| sed -E -e $'s/></>\\\n</g; s/<\/?code>//g') |
||||
|
||||
# ------------------------------------------------------------------------------ |
||||
|
||||
echo -e "# $CMD_NAME\n" |
||||
echo -e "$CMD_DESCRIPTION\n" |
||||
|
||||
paste <(echo "$OS_LIST") <(echo "$INSTALL_CMDS") --delimiter '@' | column -t -s '@' |
||||
|
Loading…
Reference in new issue