.zshrc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. ### Source local secrets
  2. [ -f ${HOME}/.config/zsh/secrets ] && . ${HOME}/.config/zsh/secrets
  3. ## local completions
  4. if [ -d "${HOME}/.config/zsh/completions" ]; then
  5. export fpath=(${HOME}/.config/zsh/completions "${fpath[@]}")
  6. fi
  7. ### edit cmds
  8. export VISUAL=vim
  9. autoload edit-command-line
  10. zle -N edit-command-line
  11. bindkey "^X^E" edit-command-line
  12. ### antibody
  13. autoload -Uz compinit
  14. compinit
  15. . ${HOME}/.config/zsh/antibody.zsh
  16. ### KiTTY completion
  17. if which kitty > /dev/null; then
  18. kitty + complete setup zsh | source /dev/stdin
  19. fi
  20. ### fasd
  21. if which fasd > /dev/null; then
  22. eval "$(fasd --init auto)"
  23. unalias sd
  24. fi
  25. ### Pipenv
  26. if which pipenv > /dev/null; then
  27. if [ -f ${HOME}/.config/zsh/pipenv.zsh ]; then
  28. eval "$(cat ${HOME}/.config/zsh/pipenv.zsh)"
  29. else
  30. eval "$(pipenv --completion)"
  31. fi
  32. fi
  33. ### virtualenvwrapper
  34. if [ -f /usr/bin/virtualenvwrapper_lazy.sh ]; then
  35. source /usr/bin/virtualenvwrapper_lazy.sh
  36. fi
  37. ### FZF
  38. [ -f ${HOME}/.config/zsh/fzf.zsh ] && . ${HOME}/.config/zsh/fzf.zsh
  39. ### ASDF
  40. if [ -d /opt/asdf-vm ]; then
  41. . /opt/asdf-vm/asdf.sh
  42. fi
  43. ### Misc
  44. ## TERM
  45. # Many target machines do not understand TERM=xterm-kitty
  46. if [ "z${TMUX}" = "z" ]; then
  47. function ssh {
  48. TERM=xterm-color /bin/ssh ${@}
  49. }
  50. fi
  51. if [[ ! -z $TMUX ]]; then
  52. export TERM=tmux-256color
  53. fi
  54. ## Editor
  55. export EDITOR=vim
  56. ## Locale
  57. export LANG=.UTF-8
  58. export LANGUAGE=en_US
  59. export LC_CTYPE=en_US.UTF-8
  60. export LC_NUMERIC=en_US.UTF-8
  61. export LC_TIME=it_IT.UTF-8
  62. export LC_COLLATE=en_US.UTF-8
  63. export LC_MONETARY=it_IT.UTF-8
  64. export LC_MESSAGES=en_US.UTF-8
  65. export LC_PAPER=it_IT.UTF-8
  66. export LC_NAME=en_US.UTF-8
  67. export LC_ADDRESS=en_US.UTF-8
  68. export LC_TELEPHONE=en_US.UTF-8
  69. export LC_MEASUREMENT=it_IT.UTF-8
  70. export LC_IDENTIFICATION=en_US.UTF-8
  71. export LC_ALL=
  72. ## Flutter && Dart
  73. export ANDROID_SDK=${HOME}/Android/Sdk
  74. export PATH=${ANDROID_SDK}/emulator:${ANDROID_SDK}/tools:$PATH
  75. export PATH=/opt/flutter/bin/:"$HOME/.pub-cache/bin":$PATH
  76. export CHROME_EXECUTABLE=/usr/bin/chromium
  77. ## Go
  78. export GOPATH=${HOME}/.go
  79. export PATH=${GOPATH}/bin:$PATH
  80. ## Ruby
  81. #export PATH=${PATH}:/home/leo/.gem/ruby/2.7.0/bin
  82. ## Elixir
  83. export ERL_AFLAGS="-kernel shell_history enabled"
  84. ## Python
  85. PYTHON_VERSION=$(python -c 'import sys; print("{}.{}".format(*sys.version_info[0:2]))')
  86. ## Aliases
  87. alias t="tmux -2"
  88. alias sy="systemctl"
  89. alias ssy="sudo systemctl"
  90. alias syu="systemctl --user"
  91. alias sl="cmatrix -b -s"
  92. alias cd..="cmatrix -b -s -C yellow"
  93. alias lt="ls -lt"
  94. alias l="ls -1"
  95. alias lh="ls -lh"
  96. alias la="ls -la"
  97. alias ll="ls -l"
  98. alias lrt="ls -lrt"
  99. alias wgpg="gpg --homedir /home/leo/.gnupg-work"
  100. alias agpg="gpg --homedir /home/leo/.gnupg-ai"
  101. alias ai_all="cat ${HOME}/Documents/personal/ai/code/prod/hosts.yml|yq '[.hosts|to_entries[]|{"key": .key, "value": .value.groups}]|from_entries'"
  102. alias pacbrowse="pacman -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pacman -Qil {} | less)'"
  103. alias pikbrowse="pikaur -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pikaur -Qil {} | less)'"
  104. alias vf="cd \$(git rev-parse --show-toplevel)"
  105. alias vvf="cd \$(${HOME}/.bin/vvf.sh)"
  106. ## Drone CLI
  107. export DRONE_SERVER=https://drone.troubles.io
  108. export DRONE_TOKEN=${drone_token}
  109. # ensure Git completion
  110. fpath+=/usr/share/git/completion
  111. ## mailbundle
  112. alias mutt="neomutt"
  113. alias mailbundle="/opt/mailbundle/config/bin/autorun"
  114. ## torbrowser
  115. export PATH=/opt/tor-browser_en-US:$PATH
  116. ## platform-tools
  117. export PATH=/opt/android-sdk/platform-tools:$PATH
  118. ## Custom functions
  119. function lookhosts {
  120. if which rg 2>&1 > /dev/null; then
  121. GREP=rg
  122. else
  123. GREP=grep
  124. fi
  125. ${GREP} $@ /etc/hosts
  126. }
  127. function reload_work_gpg {
  128. kill -9 $(ps aux|egrep "gpg-agent.*work"|grep -v grep|awk '{print $2}')
  129. }
  130. function sway-screens {
  131. local screens=$(swaymsg -t get_outputs -r)
  132. local show_active
  133. local show_inactive
  134. local var_style="plain"
  135. local active_screens=()
  136. local inactive_screens=()
  137. while [ $# -ne 0 ]; do
  138. case $1 in
  139. -a|--active)
  140. show_active=1
  141. ;;
  142. -n|--inactive)
  143. show_inactive=1
  144. ;;
  145. -s|--style)
  146. case $2 in
  147. json)
  148. var_style="json"
  149. ;;
  150. plain)
  151. ;;
  152. *)
  153. echo "unknown style ${2}"
  154. return 1
  155. ;;
  156. esac
  157. shift
  158. ;;
  159. esac
  160. shift
  161. done
  162. if [ "z${show_active}" != "z" ]; then
  163. for s in $(echo $screens|jq -r '.[] | select(.active) | .name'); do
  164. active_screens+=($s)
  165. done
  166. fi
  167. if [ "z${show_inactive}" != "z" ]; then
  168. for s in $(echo $screens|jq -r '.[] | select(.active|not) | .name'); do
  169. inactive_screens+=($s)
  170. done
  171. fi
  172. if [ "${var_style}" = "plain" ]; then
  173. if [ ${#active_screens[@]} -gt 0 ]; then
  174. echo "ACTIVE=${active_screens[@]}"
  175. fi
  176. if [ ${#inactive_screens[@]} -gt 0 ]; then
  177. echo "INACTIVE=${inactive_screens[@]}"
  178. fi
  179. else
  180. local active=""
  181. for s in $active_screens; do
  182. active+="\"$s\","
  183. done
  184. active=${active%,}
  185. local inactive=""
  186. for s in $inactive_screens; do
  187. inactive+="\"$s\","
  188. done
  189. inactive=${inactive%,}
  190. local content=""
  191. if [ "z${show_active}" != "z" ]; then
  192. content+="\"active\": [${active}],"
  193. fi
  194. if [ "z${show_inactive}" != "z" ]; then
  195. content+="\"inactive\": [${inactive}],"
  196. fi
  197. content=${content%,}
  198. echo "{${content}}" | jq
  199. fi
  200. }
  201. urlencode() {
  202. # urlencode <string>
  203. old_lc_collate=$LC_COLLATE
  204. LC_COLLATE=C
  205. local length="${#1}"
  206. for (( i = 0; i < length; i++ )); do
  207. local c="${1:$i:1}"
  208. case $c in
  209. [a-zA-Z0-9.~_-]) printf '%s' "$c" ;;
  210. *) printf '%%%02X' "'$c" ;;
  211. esac
  212. done
  213. LC_COLLATE=$old_lc_collate
  214. }
  215. urldecode() {
  216. # urldecode <string>
  217. local url_encoded="${1//+/ }"
  218. printf '%b' "${url_encoded//%/\\x}"
  219. }
  220. ## Custom completion
  221. # certo
  222. eval "$(_CERTO_COMPLETE=source_zsh certo)"
  223. ## Colored manual
  224. function _man() {
  225. man $@ | bat -p --language="man"
  226. }
  227. alias man="_man"
  228. ## Local only
  229. if [ -f ${HOME}/.zshrc.local ]; then
  230. . ${HOME}/.zshrc.local
  231. fi
  232. # [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
  233. # vim: set ft=zsh et sw=0 ts=2 sts=0: