.zshrc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. alias vim="vim -T xterm"
  107. ## Drone CLI
  108. export DRONE_SERVER=https://drone.troubles.io
  109. export DRONE_TOKEN=${drone_token}
  110. # ensure Git completion
  111. fpath+=/usr/share/git/completion
  112. ## mailbundle
  113. alias mutt="neomutt"
  114. alias mailbundle="/opt/mailbundle/config/bin/autorun"
  115. ## torbrowser
  116. export PATH=/opt/tor-browser_en-US:$PATH
  117. ## platform-tools
  118. export PATH=/opt/android-sdk/platform-tools:$PATH
  119. ## Custom functions
  120. function lookhosts {
  121. if which rg 2>&1 > /dev/null; then
  122. GREP=rg
  123. else
  124. GREP=grep
  125. fi
  126. ${GREP} $@ /etc/hosts
  127. }
  128. function reload_work_gpg {
  129. kill -9 $(ps aux|egrep "gpg-agent.*work"|grep -v grep|awk '{print $2}')
  130. }
  131. function sway-screens {
  132. local screens=$(swaymsg -t get_outputs -r)
  133. local show_active
  134. local show_inactive
  135. local var_style="plain"
  136. local active_screens=()
  137. local inactive_screens=()
  138. while [ $# -ne 0 ]; do
  139. case $1 in
  140. -a|--active)
  141. show_active=1
  142. ;;
  143. -n|--inactive)
  144. show_inactive=1
  145. ;;
  146. -s|--style)
  147. case $2 in
  148. json)
  149. var_style="json"
  150. ;;
  151. plain)
  152. ;;
  153. *)
  154. echo "unknown style ${2}"
  155. return 1
  156. ;;
  157. esac
  158. shift
  159. ;;
  160. esac
  161. shift
  162. done
  163. if [ "z${show_active}" != "z" ]; then
  164. for s in $(echo $screens|jq -r '.[] | select(.active) | .name'); do
  165. active_screens+=($s)
  166. done
  167. fi
  168. if [ "z${show_inactive}" != "z" ]; then
  169. for s in $(echo $screens|jq -r '.[] | select(.active|not) | .name'); do
  170. inactive_screens+=($s)
  171. done
  172. fi
  173. if [ "${var_style}" = "plain" ]; then
  174. if [ ${#active_screens[@]} -gt 0 ]; then
  175. echo "ACTIVE=${active_screens[@]}"
  176. fi
  177. if [ ${#inactive_screens[@]} -gt 0 ]; then
  178. echo "INACTIVE=${inactive_screens[@]}"
  179. fi
  180. else
  181. local active=""
  182. for s in $active_screens; do
  183. active+="\"$s\","
  184. done
  185. active=${active%,}
  186. local inactive=""
  187. for s in $inactive_screens; do
  188. inactive+="\"$s\","
  189. done
  190. inactive=${inactive%,}
  191. local content=""
  192. if [ "z${show_active}" != "z" ]; then
  193. content+="\"active\": [${active}],"
  194. fi
  195. if [ "z${show_inactive}" != "z" ]; then
  196. content+="\"inactive\": [${inactive}],"
  197. fi
  198. content=${content%,}
  199. echo "{${content}}" | jq
  200. fi
  201. }
  202. urlencode() {
  203. # urlencode <string>
  204. old_lc_collate=$LC_COLLATE
  205. LC_COLLATE=C
  206. local length="${#1}"
  207. for (( i = 0; i < length; i++ )); do
  208. local c="${1:$i:1}"
  209. case $c in
  210. [a-zA-Z0-9.~_-]) printf '%s' "$c" ;;
  211. *) printf '%%%02X' "'$c" ;;
  212. esac
  213. done
  214. LC_COLLATE=$old_lc_collate
  215. }
  216. urldecode() {
  217. # urldecode <string>
  218. local url_encoded="${1//+/ }"
  219. printf '%b' "${url_encoded//%/\\x}"
  220. }
  221. ## Custom completion
  222. # certo
  223. eval "$(_CERTO_COMPLETE=source_zsh certo)"
  224. ## powerline
  225. if which powerline-daemon > /dev/null; then
  226. powerline-daemon -q
  227. . /usr/lib/python${PYTHON_VERSION}/site-packages/powerline/bindings/zsh/powerline.zsh
  228. fi
  229. ## Colored manual
  230. function _man() {
  231. man $@ | bat -p --language="man"
  232. }
  233. alias man="_man"
  234. ## Local only
  235. if [ -f ${HOME}/.zshrc.local ]; then
  236. . ${HOME}/.zshrc.local
  237. fi
  238. # [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
  239. # vim: set ft=zsh et sw=0 ts=2 sts=0: