zshrc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Device-specifig setup (ignored by git)
  2. # source local config first to overwrite default theme if wanted
  3. [[ ! -f ~/.zsh_local ]] || source ~/.zsh_local
  4. ### U S E R C O N F I G ###
  5. # random string function
  6. random-string()
  7. {
  8. LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | fold -w ${1:-32} | head -n 1
  9. }
  10. # make code printable with pandocs
  11. # printable-code filename.ext [forced-extension]
  12. printable-code()
  13. {
  14. body=`cat ${1}`
  15. [[ ${1} =~ "([^.]+).([^.]+)" ]] && name=$match[1] && ext=$match[2]
  16. ext=`test -n "${2}" && echo ${2} || echo $ext`
  17. doc="# ${1}\n\`\`\`$ext\n$body\n\`\`\`"
  18. oformat=`test -n "${3}" && echo ${3} || echo "pdf"`
  19. echo $doc | pandoc -o "$name.$oformat"
  20. }
  21. # help creating links to emails
  22. # in apple mail, go to viewing → Show message headers → Custom... → Add "Message-ID"
  23. function murl () {
  24. echo message://"%3c"$@"%3e"
  25. }
  26. #
  27. # Aliases
  28. #
  29. # Git
  30. alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  31. alias glola="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all"
  32. alias imgcat="~/.dotfiles/imgcat"
  33. # Utility
  34. alias rm="nocorrect rm"
  35. # bitwarden: read session from keychain if it does not exist yet before running bitwarden
  36. alias bwl="export BW_SESSION=$(security find-generic-password -a $USER -s BW_SESSION -w) && echo \"bw session set\""
  37. #
  38. # Python
  39. #
  40. alias pip_update_all="pip install -r <(pip freeze | sed 's|==.*||') -U"
  41. #
  42. # direnv
  43. #
  44. eval "$(direnv hook zsh)"
  45. # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
  46. [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
  47. # load homebrew autocompletions
  48. if which brew > /dev/null; then
  49. fpath=($(brew --prefix)/share/zsh/site-functions $fpath)
  50. fi
  51. # zplug load
  52. if which sheldon > /dev/null; then
  53. eval "$(sheldon source)"
  54. fi
  55. zmodload zsh/complist
  56. zstyle ':completion:*' menu select
  57. # vi mode
  58. bindkey -v
  59. export KEYTIMEOUT=1
  60. # Use vim keys in tab complete menu:
  61. bindkey -M menuselect 'h' vi-backward-char
  62. bindkey -M menuselect 'k' vi-up-line-or-history
  63. bindkey -M menuselect 'l' vi-forward-char
  64. bindkey -M menuselect 'j' vi-down-line-or-history
  65. bindkey -v '^?' backward-delete-char
  66. [[ ! -f ~/.zsh_local_completions ]] || source ~/.zsh_local_completions
  67. # Better cp -- must go after compinit and stuff
  68. eval "$(zoxide init zsh)"
  69. # Store if light or dark mode is active
  70. if [[ $(defaults read -g AppleInterfaceStyle 2&> /dev/null) == "Dark" ]]
  71. then
  72. UIMODE="dark"
  73. else
  74. UIMODE="light"
  75. fi
  76. export TASKRC=~/.taskrc-${UIMODE}