New: udct.sh

This commit is contained in:
toochill 2023-08-11 03:49:43 +07:00
commit f368c89fff
2 changed files with 18 additions and 0 deletions

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# scripts
|Script|Description|Dependencies|
|-|-|-|
|[udct.sh](udct.sh)|Query a term at https://urbandictionary.com from commnd line|[jq](https://stedolan.github.io/jq)|

13
udct.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
if [ -z "$@" ]; then >&2 echo "Usage: $0 word"; exit 1; fi
if [ -z "`which jq`" ]; then
exec >&2
echo "$0: require jq"
echo "$0: check https://stedolan.github.io/jq"
fi
curl -Ls https://api.urbandictionary.com/v0/define?term="$1"\
| jq '.list[0].definition'\
| awk '{ gsub(/("|\[|\]|\\r)/, ""); gsub(/\\n/, "\n"); print }'\
| fmt -w 80