zshrc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # Device-specifig setup (ignored by git)
  2. # source local config first to overwrite default theme if wanted
  3. source ~/.zsh_local
  4. # start tmux in a nice way, if available
  5. t () {
  6. if command -v tmux>/dev/null; then
  7. [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux new-session -A -s main
  8. fi
  9. }
  10. # Source Prezto.
  11. if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
  12. source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
  13. fi
  14. ### U S E R C O N F I G ###
  15. # random string function
  16. random-string()
  17. {
  18. LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom | fold -w ${1:-32} | head -n 1
  19. }
  20. # make code printable with pandocs
  21. # printable-code filename.ext [forced-extension]
  22. printable-code()
  23. {
  24. body=`cat ${1}`
  25. [[ ${1} =~ "([^.]+).([^.]+)" ]] && name=$match[1] && ext=$match[2]
  26. ext=`test -n "${2}" && echo ${2} || echo $ext`
  27. doc="# ${1}\n\`\`\`$ext\n$body\n\`\`\`"
  28. oformat=`test -n "${3}" && echo ${3} || echo "pdf"`
  29. echo $doc | pandoc -o "$name.$oformat"
  30. }
  31. # mount a remote's ($1) host dir ($2) at $3/$2 or ~/mounts/$2 if $3 is not set
  32. mountremote () {
  33. # set the root mount dir
  34. mountroot="${3:-$HOME/mounts}";
  35. if [ -z "$2" ]; then
  36. mountpoint=$1-home
  37. else
  38. mountpoint=$1-`echo $2 | sed -E "s/\///g"`
  39. fi
  40. mkdir -p $mountroot/$mountpoint
  41. sshfs $1:$2 "$mountroot/$mountpoint" -o auto_cache,reconnect,volname=$mountpoint,no_readahead,noappledouble,nolocalcaches
  42. unset mountroot
  43. unset mountpoint
  44. }
  45. # use the symlinked ssh-auth-sock if inside tmux session otherwise update the
  46. # symlink
  47. # if [[ -f "$HOME/.ssh/ssh_auth_sock" ]]; then
  48. # export SSH_AUTH_SOCK=$HOME/.ssh/ssh_auth_sock;
  49. # fi
  50. # if we have a working socket, everything is fine
  51. if [[ -f "$SSH_AUT_SOCK" ]]; then
  52. # if the socket is working, symlink it for other uses
  53. if ssh-add -l; then
  54. ln -sf $SSH_AUTH_SOCK $HOME/.ssh/ssh_auth_sock;
  55. fi
  56. elif [[ -f "$HOME/.ssh/ssh_auth_sock" ]]; then
  57. export SSH_AUTH_SOCK=$HOME/.ssh/ssh_auth_sock
  58. fi
  59. # make the clipboard working on remote
  60. if [[ -n "$SSH_CLIENT" ]]; then
  61. SSH_IP=$(echo $SSH_CLIENT | awk '{print $1}')
  62. alias pbcopy="ssh $SSH_IP pbcopy"
  63. fi
  64. #
  65. # Aliases
  66. #
  67. # Git
  68. alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  69. 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"
  70. alias imgcat="~/.dotfiles/imgcat"
  71. # Utility
  72. alias rm="nocorrect rm"
  73. #
  74. # Python
  75. #
  76. # virtualenvwrapper
  77. if [ -f ~/virtualenvwrapper.sh ]; then
  78. source ~/virtualenvwrapper.sh
  79. export VIRTUAL_ENV_DISABLE_PROMT=yes
  80. fi
  81. if [[ -n "$ITERM_INTEGRATION" && -f ~/.iterm2_shell_integration.zsh ]]; then
  82. test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
  83. fi