dotfiles

<-- duh.
Log | Files | Refs | LICENSE

commit 1ae9af948322c85963dfff6a8e292ff8777bf39d
parent a71d78a8d38174ed65b51dbdf96d8698ed154202
Author: hhvn <dev@hhvn.uk>
Date:   Sun,  4 Jul 2021 14:02:57 +0100

.s/b/rfclookup: add -u option and improve style

Diffstat:
M.scripts/bin/rfclookup | 32+++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/.scripts/bin/rfclookup b/.scripts/bin/rfclookup @@ -18,12 +18,30 @@ # terms of the Do What The Fuck You Want To Public License, Version 2, # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. -# usage: rfclookup.sh -s <search query> -# rfclookup.sh -n <number> +index=https://www.ietf.org/download/rfc-index.txt +document="https://www.ietf.org/rfc/rfc%s.txt" -[ "$1" = "-s" ] && { - curl -i https://www.ietf.org/download/rfc-index.txt | tr '\n' '\t' | sed 's/\t\t/\n/g' | tr '\t' ' ' | tr -s ' ' | grep '^[0-9][0-9][0-9][0-9] ' | grep -iE "$2" - exit -} || { - curl https://www.ietf.org/rfc/rfc$2.txt +usage(){ + base=$(basename "$0") + printf "usage: %s -s <search query>\n" "$base" + printf "\t %s -n <number>\n" "$base" + printf "\t %s -u <number>\n" "$base" } + +case "$1" in +-s) + curl -i $index | + tr '\n' '\t' | + sed 's/\t\t/\n/g' | + tr '\t' ' ' | + tr -s ' ' | + grep '^[0-9][0-9][0-9][0-9] ' | + grep -iE "$2" + ;; +-n) + curl -s $(printf "$document\n" "$2") | less + ;; +-u) + printf "$document\n" "$2" + ;; +esac