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. export PATH="$HOME/go/bin:$PATH"
  16. # random string function
  17. random-string()
  18. {
  19. LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | fold -w ${1:-32} | head -n 1
  20. }
  21. # make code printable with pandocs
  22. # printable-code filename.ext [forced-extension]
  23. printable-code()
  24. {
  25. body=`cat ${1}`
  26. [[ ${1} =~ "([^.]+).([^.]+)" ]] && name=$match[1] && ext=$match[2]
  27. ext=`test -n "${2}" && echo ${2} || echo $ext`
  28. doc="# ${1}\n\`\`\`$ext\n$body\n\`\`\`"
  29. oformat=`test -n "${3}" && echo ${3} || echo "pdf"`
  30. echo $doc | pandoc -o "$name.$oformat"
  31. }
  32. # mount a remote's ($1) host dir ($2) at $3/$2 or ~/mounts/$2 if $3 is not set
  33. mountremote () {
  34. # set the root mount dir
  35. mountroot="${3:-$HOME/mounts}";
  36. if [ -z "$2" ]; then
  37. mountpoint=$1-home
  38. else
  39. mountpoint=$1-`echo $2 | sed -E "s/\///g"`
  40. fi
  41. mkdir -p $mountroot/$mountpoint
  42. sshfs $1:$2 "$mountroot/$mountpoint" -o auto_cache,reconnect,volname=$mountpoint,no_readahead,noappledouble,nolocalcaches
  43. unset mountroot
  44. unset mountpoint
  45. }
  46. # make the clipboard working on remote
  47. if [[ -n "$SSH_CLIENT" ]]; then
  48. SSH_IP=$(echo $SSH_CLIENT | awk '{print $1}')
  49. alias pbcopy="ssh $SSH_IP pbcopy"
  50. fi
  51. #
  52. # Aliases
  53. #
  54. # Git
  55. alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  56. 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"
  57. alias imgcat="~/.dotfiles/imgcat"
  58. # Utility
  59. alias rm="nocorrect rm"
  60. #
  61. # Python
  62. #
  63. # virtualenvwrapper
  64. if [ -f ~/virtualenvwrapper.sh ]; then
  65. source ~/virtualenvwrapper.sh
  66. export VIRTUAL_ENV_DISABLE_PROMT=yes
  67. fi
  68. if [[ -n "$ITERM_INTEGRATION" && -f ~/.iterm2_shell_integration.zsh ]]; then
  69. test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
  70. fi
  71. # a new attempt to forward ssh sockets to tmux
  72. if [[ -n "$SSH_AUTH_SOCK" ]]; then
  73. # based on/using http://stackoverflow.com/questions/21378569 and
  74. # https://gist.github.com/martijnvermaat/8070533
  75. # Fix SSH auth socket location so agent forwarding works with tmux
  76. if [[ -z "$TMUX" ]] ; then
  77. ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
  78. else
  79. export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
  80. fi
  81. fi