zshrc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 /MountPoint/$1
  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
  41. sshfs $1:$2 "$mountroot/$mountpoint" -o auto_cache,reconnect,volname=$mountpoint,no_readahead,noappledouble,nolocalcaches
  42. }
  43. # use the symlinked ssh-auth-sock if available
  44. if [[ -f "$HOME/.ssh/ssh_auth_sock" ]]; then
  45. export SSH_AUTH_SOCK=$HOME/.ssh/ssh_auth_sock;
  46. fi
  47. # make the clipboard working on remote
  48. if [[ -n "$SSH_CLIENT" ]]; then
  49. SSH_IP=$(echo $SSH_CLIENT | awk '{print $1}')
  50. alias pbcopy="ssh $SSH_IP pbcopy"
  51. fi
  52. #
  53. # Aliases
  54. #
  55. # Git
  56. alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  57. 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"
  58. alias imgcat="~/.dotfiles/imgcat"
  59. # Utility
  60. alias rm="nocorrect rm"
  61. #
  62. # Python
  63. #
  64. # virtualenvwrapper
  65. if [ -f ~/virtualenvwrapper.sh ]; then
  66. source ~/virtualenvwrapper.sh
  67. export VIRTUAL_ENV_DISABLE_PROMT=yes
  68. fi
  69. if [[ -n "$ITERM_INTEGRATION" && -f ~/.iterm2_shell_integration.zsh ]]; then
  70. test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
  71. fi