From 95b5b7682df0490b8394f077ce8ef70e23c79c62 Mon Sep 17 00:00:00 2001 From: Blallo Date: Fri, 16 Dec 2022 16:42:24 +0100 Subject: [PATCH] Add godoc and piknik and ai-related --- .zshrc | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/.zshrc b/.zshrc index 1525b9c..65fe108 100644 --- a/.zshrc +++ b/.zshrc @@ -317,6 +317,118 @@ eval "$(atuin init zsh)" bindkey '^r' _atuin_search_widget -# vim: set ft=zsh et sw=0 ts=2 sts=0: - +### broot source /home/leo/.config/broot/launcher/bash/br + +### A/I +if [ -f ${HOME}/.zshrc.ai ]; then + source ${HOME}/.zshrc.ai +fi + +### colored and fuzzy go doc +if which bat > /dev/null; then + function _godoc() { + if echo $1|grep -q -E "^([a-zA-Z0-9/]+)$"; then + go doc ${@} | bat -p -l md + elif echo $1|grep -q -E "^[a-zA-Z0-9/]+\.[a-zA-Z0-9.]+$"; then + go doc ${@} | bat -p -l go + elif echo $1|grep -q -E "^([a-zA-Z0-9/._-]+)/.*\.[a-zA-Z0-9.]+$"; then + go doc ${@} | bat -p -l go + else + go doc ${@} | bat -p -l md + fi + } +else + function _godoc() { + go doc ${@} + } +fi + +function gomodroot() { + . <(go env|grep -E "^GOMOD") + echo ${GOMOD%%go.mod} + unset GOMOD +} + +function _godocbuildcache() { + local VERSION="$(go version|awk '{print $3}')" + local DOCCACHE="${GODOC_CACHE:-${HOME}/.cache/godoc}/${VERSION}" + if [ -d ${DOCCACHE} ]; then + return 0 + fi + + echo "generating stdlib godoc cache, wait some time" 1>&2 + + mkdir -p ${DOCCACHE} + for DEP in $(go list std|grep -v -E "internal/"); do + go doc -short ${DEP}|sed -e 's/^\ *\(func\|type\|const\|var\)\ \([a-zA-Z0-9]\+\).*/\2/'|xargs -I {} echo ${DEP}.{} 2>/dev/null >> ${DOCCACHE}/stdlib.symbols + done + + echo "done generating stdlib godoc cache" 1>&2 +} + +function _godocenum() { + _godocbuildcache + local VERSION="$(go version|awk '{print $3}')" + local DOCCACHE="${GODOC_CACHE:-${HOME}/.cache/godoc}/${VERSION}" + cat ${DOCCACHE}/stdlib.symbols + + for DEP in $(go list -f '{{ join .Deps "\n" }}' $(gomodroot)/...); do + for SYM in $(go doc -short ${DEP}|sed -e 's/^\ *\(func\|type\|const\|var\)\ \([a-zA-Z0-9]\+\).*/\2/'); do + echo ${DEP}.${SYM} + done + done +} + +function godoc() { + if [ $# -eq 0 ]; then + if which bat > /dev/null; then + OBJ=$(_godocenum|fzf --height=80% --info=inline --reverse --border --margin=1 --padding=1 --preview="go doc {1}|bat --color always -p -l go") + else + OBJ=$(_godocenum|fzf --height=80% --info=inline --reverse --border --margin=1 --padding=1 --preview="go doc {1}") + fi + _godoc ${OBJ} + else + _godoc ${@} + fi +} + +### paste.sr.ht + +function pasteit() { + hut paste create ${@} +} + +### piknik + +# pko : copy to the clipboard +function pko() { + echo "$*" | piknik -copy +} + +# pkf : copy the content of to the clipboard +function pkf() { + piknik -copy < $1 +} + +# pkc : read the content to copy to the clipboard from STDIN +alias pkc='piknik -copy' + +# pkp : paste the clipboard content +alias pkp='piknik -paste' + +# pkm : move the clipboard content +alias pkm='piknik -move' + +# pkz : delete the clipboard content +alias pkz='piknik -copy < /dev/null' + +# pkfr [] : send a whole directory to the clipboard, as a tar archive +function pkfr() { + tar czpvf - ${1:-.} | piknik -copy +} + +# pkpr : extract clipboard content sent using the pkfr command +alias pkpr='piknik -paste | tar xzpvf -' + +# vim: set ft=zsh et sw=0 ts=2 sts=0: