Compare commits

...

5 commits

Author SHA1 Message Date
771b32ef53
piknik 2022-12-16 16:46:23 +01:00
e62e1687a3
paste.sr.ht 2022-12-16 16:46:10 +01:00
c1ff140bbe
godoc 2022-12-16 16:45:52 +01:00
34a70cac5c
A/I only 2022-12-16 16:45:27 +01:00
7985c5af47
Cosmetic 2022-12-16 16:45:03 +01:00

116
.zshrc
View file

@ -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 <content> : copy <content> to the clipboard
function pko() {
echo "$*" | piknik -copy
}
# pkf <file> : copy the content of <file> 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 [<dir>] : 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: