zconfig/.zshrc

425 lines
9.3 KiB
Bash
Raw Normal View History

2020-04-30 13:44:51 +02:00
### Source local secrets
[ -f ${HOME}/.config/zsh/secrets ] && . ${HOME}/.config/zsh/secrets
## local completions
if [ -d "${HOME}/.config/zsh/completions" ]; then
export fpath=(${HOME}/.config/zsh/completions "${fpath[@]}")
fi
2020-05-08 15:57:53 +02:00
### edit cmds
2022-10-06 16:35:12 +02:00
export VISUAL=nvim
2020-05-08 15:57:53 +02:00
autoload edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line
2020-04-29 12:54:10 +02:00
### antibody
autoload -Uz compinit
compinit
. ${HOME}/.config/zsh/antibody.zsh
2019-11-18 15:36:09 +01:00
2022-10-06 16:35:12 +02:00
### antidote
#. ~/.antidote/antidote.zsh
#antidote load
#. ~/.zsh_plugins.zsh
2020-04-29 12:54:10 +02:00
### fasd
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
if which fasd > /dev/null; then
eval "$(fasd --init auto)"
unalias sd
2019-11-18 15:36:09 +01:00
fi
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
### Pipenv
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
if which pipenv > /dev/null; then
if [ -f ${HOME}/.config/zsh/pipenv.zsh ]; then
eval "$(cat ${HOME}/.config/zsh/pipenv.zsh)"
else
eval "$(pipenv --completion)"
fi
fi
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
### virtualenvwrapper
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
if [ -f /usr/bin/virtualenvwrapper_lazy.sh ]; then
source /usr/bin/virtualenvwrapper_lazy.sh
fi
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
### FZF
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
[ -f ${HOME}/.config/zsh/fzf.zsh ] && . ${HOME}/.config/zsh/fzf.zsh
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
### ASDF
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
if [ -d /opt/asdf-vm ]; then
. /opt/asdf-vm/asdf.sh
fi
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
### Misc
## TERM
# Many target machines do not understand TERM=xterm-kitty
2019-11-18 15:36:09 +01:00
if [ "z${TMUX}" = "z" ]; then
function ssh {
2020-04-29 12:54:10 +02:00
TERM=xterm-color /bin/ssh ${@}
2019-11-18 15:36:09 +01:00
}
fi
2018-07-13 18:08:38 +02:00
2019-11-18 15:36:09 +01:00
if [[ ! -z $TMUX ]]; then
export TERM=tmux-256color
2022-01-29 17:24:54 +01:00
export TMUX_BASE=$(tmux display -p '#{pane_current_path}')
2019-11-18 15:36:09 +01:00
fi
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
## Editor
2022-10-06 16:35:12 +02:00
export EDITOR=nvim
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
## Locale
export LANG=.UTF-8
export LANGUAGE=en_US
export LC_CTYPE=en_US.UTF-8
export LC_NUMERIC=en_US.UTF-8
export LC_TIME=it_IT.UTF-8
export LC_COLLATE=en_US.UTF-8
export LC_MONETARY=it_IT.UTF-8
export LC_MESSAGES=en_US.UTF-8
export LC_PAPER=it_IT.UTF-8
export LC_NAME=en_US.UTF-8
export LC_ADDRESS=en_US.UTF-8
export LC_TELEPHONE=en_US.UTF-8
export LC_MEASUREMENT=it_IT.UTF-8
export LC_IDENTIFICATION=en_US.UTF-8
export LC_ALL=
2019-11-18 15:36:09 +01:00
## Flutter && Dart
2020-04-29 12:54:10 +02:00
export ANDROID_SDK=${HOME}/Android/Sdk
2021-03-18 11:14:20 +01:00
export PATH=${ANDROID_SDK}/emulator:${ANDROID_SDK}/tools:$PATH
export PATH=/opt/flutter/bin/:"$HOME/.pub-cache/bin":$PATH
export CHROME_EXECUTABLE=/usr/bin/chromium
2018-07-13 18:08:38 +02:00
## Go
2020-04-29 12:54:10 +02:00
export GOPATH=${HOME}/.go
2021-03-18 11:14:40 +01:00
export PATH=${GOPATH}/bin:$PATH
2018-07-13 18:08:38 +02:00
2020-05-08 15:57:53 +02:00
## Ruby
2021-03-18 11:15:19 +01:00
#export PATH=${PATH}:/home/leo/.gem/ruby/2.7.0/bin
2020-05-08 15:57:53 +02:00
2019-11-18 15:36:09 +01:00
## Elixir
export ERL_AFLAGS="-kernel shell_history enabled"
2021-03-18 11:15:54 +01:00
## Python
PYTHON_VERSION=$(python -c 'import sys; print("{}.{}".format(*sys.version_info[0:2]))')
2018-07-13 18:08:38 +02:00
## Aliases
alias t="tmux -2"
alias sy="systemctl"
alias ssy="sudo systemctl"
2019-11-18 15:36:09 +01:00
alias syu="systemctl --user"
2018-07-13 18:08:38 +02:00
alias sl="cmatrix -b -s"
alias cd..="cmatrix -b -s -C yellow"
alias lt="ls -lt"
2020-05-08 15:57:53 +02:00
alias l="ls -1"
2018-07-13 18:08:38 +02:00
alias lh="ls -lh"
alias la="ls -la"
alias ll="ls -l"
alias lrt="ls -lrt"
2022-01-29 17:24:54 +01:00
alias wgpg="gpg --homedir /home/leo/.gnupg-sysdig"
2019-11-18 15:36:09 +01:00
alias agpg="gpg --homedir /home/leo/.gnupg-ai"
2022-10-06 16:35:12 +02:00
alias ai_all="cat ${HOME}/code/ai/prod/hosts.yml|yq '[.hosts|to_entries[]|{"key": .key, "value": .value.groups}]|from_entries'"
2020-04-29 12:54:10 +02:00
alias pacbrowse="pacman -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pacman -Qil {} | less)'"
alias pikbrowse="pikaur -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pikaur -Qil {} | less)'"
alias vf="cd \$(git rev-parse --show-toplevel)"
alias vvf="cd \$(${HOME}/.bin/vvf.sh)"
2021-05-25 23:03:22 +02:00
alias vim="vim -T xterm"
2019-11-18 15:36:09 +01:00
2020-04-29 12:54:10 +02:00
## Drone CLI
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
export DRONE_SERVER=https://drone.troubles.io
2020-04-30 13:44:51 +02:00
export DRONE_TOKEN=${drone_token}
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
# ensure Git completion
fpath+=/usr/share/git/completion
2018-07-13 18:08:38 +02:00
2020-04-29 12:54:10 +02:00
## mailbundle
2022-01-29 17:24:54 +01:00
export MAILDIR="${HOME}/Mail"
2018-07-13 18:08:38 +02:00
alias mutt="neomutt"
2022-01-29 17:24:54 +01:00
alias mailbundle="${MAILDIR}/mailbundle/config/bin/autorun"
2019-11-18 15:36:09 +01:00
2020-04-29 12:54:10 +02:00
## torbrowser
2021-03-18 11:16:43 +01:00
export PATH=/opt/tor-browser_en-US:$PATH
2019-11-18 15:36:09 +01:00
2020-04-29 12:54:10 +02:00
## platform-tools
2021-03-18 11:16:43 +01:00
export PATH=/opt/android-sdk/platform-tools:$PATH
2019-11-18 15:36:09 +01:00
2020-04-29 12:54:10 +02:00
## Custom functions
2023-05-05 15:37:35 +02:00
function ,lookhosts {
2019-11-18 15:36:09 +01:00
if which rg 2>&1 > /dev/null; then
GREP=rg
else
GREP=grep
fi
${GREP} $@ /etc/hosts
}
2023-05-05 15:37:35 +02:00
function ,sway-screens {
2020-04-30 12:32:48 +02:00
local screens=$(swaymsg -t get_outputs -r)
local show_active
local show_inactive
local var_style="plain"
local active_screens=()
local inactive_screens=()
while [ $# -ne 0 ]; do
case $1 in
-a|--active)
show_active=1
;;
-n|--inactive)
show_inactive=1
;;
-s|--style)
case $2 in
json)
var_style="json"
;;
plain)
;;
*)
echo "unknown style ${2}"
return 1
;;
esac
shift
;;
esac
shift
done
if [ "z${show_active}" != "z" ]; then
for s in $(echo $screens|jq -r '.[] | select(.active) | .name'); do
active_screens+=($s)
done
fi
if [ "z${show_inactive}" != "z" ]; then
for s in $(echo $screens|jq -r '.[] | select(.active|not) | .name'); do
inactive_screens+=($s)
done
fi
if [ "${var_style}" = "plain" ]; then
if [ ${#active_screens[@]} -gt 0 ]; then
echo "ACTIVE=${active_screens[@]}"
fi
if [ ${#inactive_screens[@]} -gt 0 ]; then
echo "INACTIVE=${inactive_screens[@]}"
fi
else
local active=""
for s in $active_screens; do
active+="\"$s\","
done
active=${active%,}
local inactive=""
for s in $inactive_screens; do
inactive+="\"$s\","
done
inactive=${inactive%,}
local content=""
if [ "z${show_active}" != "z" ]; then
content+="\"active\": [${active}],"
fi
if [ "z${show_inactive}" != "z" ]; then
content+="\"inactive\": [${inactive}],"
fi
content=${content%,}
echo "{${content}}" | jq
fi
}
2023-05-05 15:37:35 +02:00
function ,urlencode() {
2021-03-18 11:17:18 +01:00
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:$i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf '%s' "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
}
urldecode() {
# urldecode <string>
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}
2022-01-29 17:24:54 +01:00
ce() {
if [ "z$TMUX" != "z" ] && [ "z$TMUX_BASE" != "z" ] ; then
cd $()
cd $TMUX_BASE
else
cd
fi
}
2020-04-29 12:54:10 +02:00
## Custom completion
# certo
2021-06-09 11:18:57 +02:00
if which certo > /dev/null; then
eval "$(_CERTO_COMPLETE=source_zsh certo)"
fi
2018-07-13 18:08:38 +02:00
2021-03-18 11:18:11 +01:00
## powerline
if which powerline-daemon > /dev/null; then
powerline-daemon -q
. /usr/lib/python${PYTHON_VERSION}/site-packages/powerline/bindings/zsh/powerline.zsh
fi
2021-03-18 11:17:46 +01:00
## Colored manual
2022-01-29 17:24:54 +01:00
function color_man() {
2021-03-18 11:17:46 +01:00
man $@ | bat -p --language="man"
}
2022-01-29 17:24:54 +01:00
alias man="color_man"
2021-03-18 11:17:46 +01:00
2020-05-08 15:57:53 +02:00
## Local only
if [ -f ${HOME}/.zshrc.local ]; then
. ${HOME}/.zshrc.local
fi
2021-06-09 11:18:34 +02:00
### atuin (shell history)
export ATUIN_NOBIND="true"
eval "$(atuin init zsh)"
bindkey '^r' _atuin_search_widget
2021-03-18 11:13:16 +01:00
2022-12-16 16:45:03 +01:00
### broot
2022-01-29 17:24:54 +01:00
source /home/leo/.config/broot/launcher/bash/br
2022-12-16 16:45:03 +01:00
2022-12-16 16:45:27 +01:00
### A/I
if [ -f ${HOME}/.zshrc.ai ]; then
source ${HOME}/.zshrc.ai
fi
2022-12-16 16:45:03 +01:00
2022-12-16 16:45:52 +01:00
### 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
}
2023-05-05 15:37:35 +02:00
function ,godoc() {
2022-12-16 16:45:52 +01:00
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
}
2022-12-16 16:46:10 +01:00
### paste.sr.ht
2023-05-05 15:37:35 +02:00
function ,pasteit() {
2022-12-16 16:46:10 +01:00
hut paste create ${@}
}
2022-12-16 16:46:23 +01:00
### piknik
# pko <content> : copy <content> to the clipboard
2023-05-05 15:37:35 +02:00
function ,pko() {
2022-12-16 16:46:23 +01:00
echo "$*" | piknik -copy
}
# pkf <file> : copy the content of <file> to the clipboard
2023-05-05 15:37:35 +02:00
function ,pkf() {
2022-12-16 16:46:23 +01:00
piknik -copy < $1
}
# pkc : read the content to copy to the clipboard from STDIN
2023-05-05 15:37:35 +02:00
alias ,pkc='piknik -copy'
2022-12-16 16:46:23 +01:00
# pkp : paste the clipboard content
2023-05-05 15:37:35 +02:00
alias ,pkp='piknik -paste'
2022-12-16 16:46:23 +01:00
# pkm : move the clipboard content
2023-05-05 15:37:35 +02:00
alias ,pkm='piknik -move'
2022-12-16 16:46:23 +01:00
# pkz : delete the clipboard content
2023-05-05 15:37:35 +02:00
alias ,pkz='piknik -copy < /dev/null'
2022-12-16 16:46:23 +01:00
# pkfr [<dir>] : send a whole directory to the clipboard, as a tar archive
2023-05-05 15:37:35 +02:00
function ,pkfr() {
2022-12-16 16:46:23 +01:00
tar czpvf - ${1:-.} | piknik -copy
}
# pkpr : extract clipboard content sent using the pkfr command
2023-05-05 15:37:35 +02:00
alias ,pkpr='piknik -paste | tar xzpvf -'
2022-12-16 16:46:23 +01:00
2022-12-16 16:45:03 +01:00
# vim: set ft=zsh et sw=0 ts=2 sts=0: