You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
6.6 KiB

  1. # Directly start sway if we're on tty1
  2. if [ "$(tty)" = "/dev/tty1" ]; then
  3. exec sway-run
  4. fi
  5. # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
  6. # Initialization code that may require console input (password prompts, [y/n]
  7. # confirmations, etc.) must go above this block, everything else may go below.
  8. if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  9. source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
  10. fi
  11. # Back out if we're surrounded by Emacs
  12. [ "$TERM" = "eterm-color" ] && exec bash
  13. [ "$TERM" = "xterm-termite" ] && export TERM=xterm-256color
  14. # Back out if we are in a Emacs tramp session
  15. if [[ $TERM == "eterm-color " ]] || [[ $TERM == "dumb" ]]; then
  16. unsetopt zle
  17. PS1='$ '
  18. return
  19. fi
  20. plugins=(fzf fasd tmuxinator)
  21. fpath=( ~/.kubectx/completion "${fpath[@]}" )
  22. ZSH_CUSTOM="${HOME}/.zsh-custom"
  23. {{- if eq .chezmoi.fullHostname "mcnaught.uberspace.de" }}
  24. ZSH_THEME="jreese"
  25. {{ else }}
  26. ZSH_THEME="powerlevel10k/powerlevel10k"
  27. {{- end }}
  28. FZF_MARKS_FILE="${HOME}/.config/fzf/${HOST}"
  29. export ZSH=${HOME}/.oh-my-zsh
  30. export DISABLE_AUTO_UPDATE="true"
  31. source $ZSH/oh-my-zsh.sh
  32. source $ZSH_CUSTOM/plugins/fzf-marks/fzf-marks.plugin.zsh
  33. source $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh
  34. {{- if or (eq .chezmoi.hostname "pierogi") (eq .chezmoi.hostname "apfelstrudel") }}
  35. export GPG_TTY="$(tty)"
  36. export SSH_AUTH_SOCK="/run/user/$UID/gnupg/S.gpg-agent.ssh"
  37. gpg-connect-agent updatestartuptty /bye &> /dev/null
  38. {{- end }}
  39. alias va="vagrant"
  40. alias bi="bundle install"
  41. alias be="bundle exec"
  42. alias ber="bundle exec rake"
  43. alias e=$EDITOR
  44. alias vim=nvim
  45. alias ssh-yop="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
  46. alias scp-yop="scp -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
  47. alias docker-rm-stopped="docker rm (docker ps -a -q)"
  48. alias docker-rm-dangling="docker rmi (docker images -q -f dangling=true)"
  49. alias dco="docker-compose"
  50. alias dcorrm="docker-compose run --rm"
  51. alias emacseval="emacs -batch -l ~/.emacs.d/init.el -eval '(org-batch-agenda "a")'"
  52. alias drri="docker run --rm -ti"
  53. alias dry="drri -v /var/run/docker.sock:/var/run/docker.sock skanehira/docui"
  54. alias k=kubectl
  55. alias kgp="kubectl get pods"
  56. alias krs="kubectl rollout status"
  57. alias g=git
  58. alias git-cleanup-merged-branches="git fetch -va && git branch --merged | egrep -v '(^\*|master)' | xargs git branch -d"
  59. alias wttr="curl 'wttr.in/Neuwied?1pQF&lang=de'"
  60. alias termbin="nc termbin.com 9999"
  61. alias gp="gopass"
  62. alias hl="hledger"
  63. alias cm="chezmoi"
  64. alias cm-add-changed-file="cm add \$(cm diff|grep ^install|cut -d ' ' -f 5|fzf)"
  65. alias cm-private="chezmoi -S ~/.local/share/chezmoi-private"
  66. alias ls="exa --icons"
  67. alias kn="kubens"
  68. alias alfaview-logfile="/usr/bin/env ls -d -- ~/.local/share/alfaview-staging/logs/*.log|tail -n 1"
  69. alias ta="tmux attach -t \$(tmux ls -F '#{session_name}' | fzf)"
  70. alias gf="git fetch -a && git rebase && git --no-pager today-all && echo -n '\n'"
  71. alias gbb="BRANCH=\$(git for-each-ref refs/heads/ --format='%(refname:short)' | fzf); git fetch origin \${BRANCH} && git checkout \${BRANCH}"
  72. # Global Aliases
  73. alias -g B="|bat"
  74. alias -g baml="|bat -l yaml"
  75. alias -g obaml="-o yaml|bat -l yaml"
  76. # Switch between multiple kubeconfigs, stored in gopass
  77. kp() { export KUBECONFIG=/dev/shm/kubeconfig-${1} && touch $KUBECONFIG && chmod 0500 $KUBECONFIG && gopass $(gopass ls -f | fzf --query "'${1} kubeconfig" --select-1) > $KUBECONFIG && source <(kubectl completion zsh) }
  78. # Give my <tab> key some rest
  79. kfp() { kubectl get pod -l app="${1:-$(basename $PWD)}" -o jsonpath="{.items[0].metadata.name}" }
  80. kpe() { kubectl exec -ti $(kfp ${1:-$(basename $PWD)}) $2 }
  81. kpb() { kpe ${1:-$(basename $PWD)} bash }
  82. kgc() { k get pod $(kfp) -o jsonpath="{.spec.containers[*].name}" | tr -s '[[:space:]]' '\n' }
  83. kgl() { kubectl logs -f $(kfp ${1:-$(basename $PWD)}) $(kgc|fzf) }
  84. letterup() {
  85. if [[ ! -a $1 ]]; then
  86. take $1;
  87. cp ~/Documents/Personal/Brief-Vorlage/2021-LaTeX-Reworked/template.tex brief.tex;
  88. else
  89. cd $1;
  90. fi;
  91. tmuxinator start letter;
  92. }
  93. letterbuild() {
  94. podman run -e VERBOSE=false -i --rm letter < $(*.tex) > $(basename *tex .tex)
  95. }
  96. # Pretty up FZF
  97. export FZF_DEFAULT_OPTS='
  98. --prompt=" "
  99. --border
  100. --height="40%"
  101. --layout=reverse
  102. --color=bg+:#f0f0f1,bg:#fafafa,spinner:#0184bc,hl:#4078f2
  103. --color=fg:#696c77,header:#4078f2,info:#c18401,pointer:#0184bc
  104. --color=marker:#0184bc,fg+:#202227,prompt:#c18401,hl+:#4078f2
  105. '
  106. # Via @dohq
  107. # https://gist.github.com/dohq/1dc702cc0b46eb62884515ea52330d60
  108. function fzf-ssh () {
  109. local selected_host=$(grep "Host " ~/.ssh/config | grep -v '*' | cut -b 6- | fzf --reverse --height=20 --query "$LBUFFER")
  110. if [ -n "$selected_host" ]; then
  111. BUFFER="ssh ${selected_host}"
  112. zle accept-line
  113. fi
  114. zle reset-prompt
  115. }
  116. # Only load kubectl completion when needed. I's bog-slow
  117. if [[ -f $KUBECONFIG ]]; then
  118. source <(kubectl completion zsh);
  119. fi;
  120. zle -N fzf-ssh
  121. bindkey '\es' fzf-ssh
  122. # Tmux Quick Keys
  123. bindkey -s '\egtn' 'tn^M'
  124. bindkey -s '\egta' "ta^M"
  125. # Git Quick Keys
  126. bindkey -s '\eggf' "gf^M"
  127. bindkey -s '\eggp' "git push^M"
  128. bindkey -s '\eggs' "git status^M"
  129. bindkey -s '\egbb' "gbb^M"
  130. # Yaml Engineering
  131. bindkey -s '\egba' "baml^M"
  132. bindkey -s '\egoba' "obaml^M"
  133. # Kubeshizzle
  134. bindkey -s '\egkx' "kubectx^M"
  135. bindkey -s '\egkn' "kubens^M"
  136. function fzf-vm () {
  137. local selected_vm=$(grep "Host " ~/.ssh/config | grep -oP "vm-(\w+)" | sort -u | cut -b 4- | fzf --reverse --height=20 --query "$LBUFFER")
  138. if [ -n "$selected_vm" ]; then
  139. BUFFER="vm ${selected_vm} ''"
  140. zle accept-line
  141. fi
  142. zle reset-prompt
  143. }
  144. zle -N fzf-vm
  145. bindkey '\ev' fzf-vm
  146. # rg on Asteroids
  147. rga-fzf() {
  148. RG_PREFIX="rga --files-with-matches"
  149. local file
  150. file="$(
  151. FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
  152. fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
  153. --phony -q "$1" \
  154. --bind "change:reload:$RG_PREFIX {q}" \
  155. --preview-window="70%:wrap"
  156. )" &&
  157. echo "opening $file" &&
  158. xdg-open "$file"
  159. }
  160. # Via @leahneukirchen
  161. autoload -Uz copy-earlier-word
  162. zle -N copy-earlier-word
  163. bindkey "^[m" copy-earlier-word
  164. # TODO: Revisit later once foot has an option to ignore shift / control
  165. # or I decide to actually use those mappings
  166. # https://codeberg.org/dnkl/foot/issues/628 is ignored
  167. bindkey "\e[27;2;13~" accept-line # shift+return
  168. bindkey "\e[27;5;13~" accept-line # ctrl+return
  169. if [ -f ~/Code/architecture/bin/ia ]; then
  170. source <(~/Code/architecture/bin/ia completion)
  171. fi;
  172. if [ -f ${HOME}/Code/infrastructure-cli/Rakefile ]; then
  173. alias chuck="rake -f ${HOME}/Code/infrastructure-cli/Rakefile"
  174. fi;
  175. source ~/.zsh-custom/plugins/
  176. source ~/.p10k.zsh
  177. autoload -U compinit && compinit