1
0

zshrc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_ALL=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. # make the clipboard working on remote
  46. if [[ -n "$SSH_CLIENT" ]]; then
  47. SSH_IP=$(echo $SSH_CLIENT | awk '{print $1}')
  48. alias pbcopy="ssh $SSH_IP pbcopy"
  49. fi
  50. #
  51. # Aliases
  52. #
  53. # Git
  54. alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  55. 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"
  56. alias imgcat="~/.dotfiles/imgcat"
  57. # Utility
  58. alias rm="nocorrect rm"
  59. #
  60. # Python
  61. #
  62. # virtualenvwrapper
  63. if [ -f ~/virtualenvwrapper.sh ]; then
  64. source ~/virtualenvwrapper.sh
  65. export VIRTUAL_ENV_DISABLE_PROMT=yes
  66. fi
  67. if [[ -n "$ITERM_INTEGRATION" && -f ~/.iterm2_shell_integration.zsh ]]; then
  68. test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
  69. fi
  70. # a new attempt to forward ssh sockets to tmux
  71. if [[ -n "$SSH_AUTH_SOCK" ]]; then
  72. # based on/using http://stackoverflow.com/questions/21378569 and
  73. # https://gist.github.com/martijnvermaat/8070533
  74. # Fix SSH auth socket location so agent forwarding works with tmux
  75. if [[ -z "$TMUX" ]] ; then
  76. ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
  77. else
  78. export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
  79. fi
  80. fi