]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/hitokoto/hitokoto.plugin.zsh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / hitokoto / hitokoto.plugin.zsh
1 if ! (( $+commands[curl] )); then
2   echo "hitokoto plugin needs curl to work" >&2
3   return
4 fi
5
6 function hitokoto {
7   setopt localoptions nopromptsubst
8
9   # Get hitokoto data
10   local -a data
11   data=("${(ps:\n:)"$(command curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | command jq -j '.hitokoto+"\n"+.from')"}")
12
13   # Exit if could not fetch hitokoto
14   [[ -n "$data" ]] || return 0
15
16   local quote="${data[1]}" author="${data[2]}"
17   print -P "%F{3}${author}%f: â€œ%F{5}${quote}%f”"
18 }