Maxim Likhachev 4 years ago
parent
commit
65d99825b4
  1. 1
      README.md
  2. 43
      scripts/cnf

1
README.md

@ -19,6 +19,7 @@ will create the symbolic link for each script in the \<path> directory. @@ -19,6 +19,7 @@ will create the symbolic link for each script in the \<path> directory.
## Shell
- [cnf](scripts/cnf) is a command line interface for [command-not-found website](https://command-not-found.com).
- [dus](scripts/dus) shows the directories' sizes sorted in descending order (see also [dust](https://github.com/bootandy/dust)).
- [ext](scripts/ext) unpacks archives.
- [pk](scripts/pk) creates archives of various types.

43
scripts/cnf

@ -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…
Cancel
Save