324 lines
6.7 KiB
Bash
324 lines
6.7 KiB
Bash
### 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
|
|
|
|
### edit cmds
|
|
export VISUAL=nvim
|
|
autoload edit-command-line
|
|
zle -N edit-command-line
|
|
bindkey "^X^E" edit-command-line
|
|
### antibody
|
|
autoload -Uz compinit
|
|
compinit
|
|
. ${HOME}/.config/zsh/antibody.zsh
|
|
|
|
### antidote
|
|
#. ~/.antidote/antidote.zsh
|
|
#antidote load
|
|
|
|
#. ~/.zsh_plugins.zsh
|
|
|
|
### KiTTY completion
|
|
|
|
if which kitty > /dev/null; then
|
|
kitty + complete setup zsh | source /dev/stdin
|
|
fi
|
|
|
|
### fasd
|
|
|
|
if which fasd > /dev/null; then
|
|
eval "$(fasd --init auto)"
|
|
unalias sd
|
|
fi
|
|
|
|
### Pipenv
|
|
|
|
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
|
|
|
|
### virtualenvwrapper
|
|
|
|
if [ -f /usr/bin/virtualenvwrapper_lazy.sh ]; then
|
|
source /usr/bin/virtualenvwrapper_lazy.sh
|
|
fi
|
|
|
|
|
|
### FZF
|
|
|
|
[ -f ${HOME}/.config/zsh/fzf.zsh ] && . ${HOME}/.config/zsh/fzf.zsh
|
|
|
|
### ASDF
|
|
|
|
if [ -d /opt/asdf-vm ]; then
|
|
. /opt/asdf-vm/asdf.sh
|
|
fi
|
|
|
|
### Misc
|
|
|
|
## TERM
|
|
# Many target machines do not understand TERM=xterm-kitty
|
|
if [ "z${TMUX}" = "z" ]; then
|
|
function ssh {
|
|
TERM=xterm-color /bin/ssh ${@}
|
|
}
|
|
fi
|
|
|
|
if [[ ! -z $TMUX ]]; then
|
|
export TERM=tmux-256color
|
|
export TMUX_BASE=$(tmux display -p '#{pane_current_path}')
|
|
fi
|
|
|
|
## Editor
|
|
export EDITOR=nvim
|
|
|
|
## 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=
|
|
|
|
## Flutter && Dart
|
|
export ANDROID_SDK=${HOME}/Android/Sdk
|
|
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
|
|
|
|
## Go
|
|
export GOPATH=${HOME}/.go
|
|
export PATH=${GOPATH}/bin:$PATH
|
|
|
|
## Ruby
|
|
#export PATH=${PATH}:/home/leo/.gem/ruby/2.7.0/bin
|
|
|
|
## Elixir
|
|
export ERL_AFLAGS="-kernel shell_history enabled"
|
|
|
|
## Python
|
|
PYTHON_VERSION=$(python -c 'import sys; print("{}.{}".format(*sys.version_info[0:2]))')
|
|
|
|
## Aliases
|
|
alias t="tmux -2"
|
|
alias sy="systemctl"
|
|
alias ssy="sudo systemctl"
|
|
alias syu="systemctl --user"
|
|
alias sl="cmatrix -b -s"
|
|
alias cd..="cmatrix -b -s -C yellow"
|
|
alias lt="ls -lt"
|
|
alias l="ls -1"
|
|
alias lh="ls -lh"
|
|
alias la="ls -la"
|
|
alias ll="ls -l"
|
|
alias lrt="ls -lrt"
|
|
alias wgpg="gpg --homedir /home/leo/.gnupg-sysdig"
|
|
alias agpg="gpg --homedir /home/leo/.gnupg-ai"
|
|
alias ai_all="cat ${HOME}/code/ai/prod/hosts.yml|yq '[.hosts|to_entries[]|{"key": .key, "value": .value.groups}]|from_entries'"
|
|
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)"
|
|
alias vim="vim -T xterm"
|
|
|
|
## Drone CLI
|
|
|
|
export DRONE_SERVER=https://drone.troubles.io
|
|
export DRONE_TOKEN=${drone_token}
|
|
|
|
# ensure Git completion
|
|
fpath+=/usr/share/git/completion
|
|
|
|
## mailbundle
|
|
export MAILDIR="${HOME}/Mail"
|
|
alias mutt="neomutt"
|
|
alias mailbundle="${MAILDIR}/mailbundle/config/bin/autorun"
|
|
|
|
## torbrowser
|
|
export PATH=/opt/tor-browser_en-US:$PATH
|
|
|
|
## platform-tools
|
|
export PATH=/opt/android-sdk/platform-tools:$PATH
|
|
|
|
## Custom functions
|
|
function lookhosts {
|
|
if which rg 2>&1 > /dev/null; then
|
|
GREP=rg
|
|
else
|
|
GREP=grep
|
|
fi
|
|
${GREP} $@ /etc/hosts
|
|
}
|
|
|
|
function reload_work_gpg {
|
|
kill -9 $(ps aux|egrep "gpg-agent.*work"|grep -v grep|awk '{print $2}')
|
|
}
|
|
|
|
function sway-screens {
|
|
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
|
|
}
|
|
|
|
urlencode() {
|
|
# 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}"
|
|
}
|
|
|
|
ce() {
|
|
if [ "z$TMUX" != "z" ] && [ "z$TMUX_BASE" != "z" ] ; then
|
|
cd $()
|
|
cd $TMUX_BASE
|
|
else
|
|
cd
|
|
fi
|
|
}
|
|
|
|
## Custom completion
|
|
# certo
|
|
if which certo > /dev/null; then
|
|
eval "$(_CERTO_COMPLETE=source_zsh certo)"
|
|
fi
|
|
|
|
## powerline
|
|
|
|
if which powerline-daemon > /dev/null; then
|
|
powerline-daemon -q
|
|
. /usr/lib/python${PYTHON_VERSION}/site-packages/powerline/bindings/zsh/powerline.zsh
|
|
fi
|
|
|
|
## Colored manual
|
|
|
|
function color_man() {
|
|
man $@ | bat -p --language="man"
|
|
}
|
|
|
|
alias man="color_man"
|
|
|
|
## Local only
|
|
|
|
if [ -f ${HOME}/.zshrc.local ]; then
|
|
. ${HOME}/.zshrc.local
|
|
fi
|
|
|
|
### atuin (shell history)
|
|
export ATUIN_NOBIND="true"
|
|
eval "$(atuin init zsh)"
|
|
|
|
bindkey '^r' _atuin_search_widget
|
|
|
|
### broot
|
|
source /home/leo/.config/broot/launcher/bash/br
|
|
|
|
|
|
# vim: set ft=zsh et sw=0 ts=2 sts=0:
|