Update 30.01.2022
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
if ! (( $+commands[curl] )); then
|
||||
echo "hitokoto plugin needs curl to work" >&2
|
||||
return
|
||||
echo "hitokoto plugin needs curl to work" >&2
|
||||
return
|
||||
fi
|
||||
|
||||
function hitokoto {
|
||||
emulate -L zsh
|
||||
Q=$(curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | jq -j '.hitokoto+"\t"+.from')
|
||||
setopt localoptions nopromptsubst
|
||||
|
||||
TXT=$(echo "$Q" | awk -F '\t' '{print $1}')
|
||||
WHO=$(echo "$Q" | awk -F '\t' '{print $2}')
|
||||
# Get hitokoto data
|
||||
local -a data
|
||||
data=("${(ps:\n:)"$(command curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | command jq -j '.hitokoto+"\n"+.from')"}")
|
||||
|
||||
[[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”"
|
||||
# Exit if could not fetch hitokoto
|
||||
[[ -n "$data" ]] || return 0
|
||||
|
||||
local quote="${data[1]}" author="${data[2]}"
|
||||
print -P "%F{3}${author}%f: “%F{5}${quote}%f”"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user