hitokoto.plugin.zsh 413 B

1234567891011121314
  1. if ! (( $+commands[curl] )); then
  2. echo "hitokoto plugin needs curl to work" >&2
  3. return
  4. fi
  5. function hitokoto {
  6. emulate -L zsh
  7. Q=$(curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | jq -j '.hitokoto+"\t"+.from')
  8. TXT=$(echo "$Q" | awk -F '\t' '{print $1}')
  9. WHO=$(echo "$Q" | awk -F '\t' '{print $2}')
  10. [[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”"
  11. }