1
0

zshrc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. if [ -z "$2" ]; then
  34. mountpoint=$1-home
  35. else
  36. mountpoint=$1-`echo $2 | sed -E "s/\///g"`
  37. fi
  38. mkdir -p /MountPoints/$mountpoint
  39. sshfs $1:$2 "/MountPoints/$mountpoint" -o auto_cache,reconnect,volname=$mountpoint,no_readahead,noappledouble,nolocalcaches
  40. }
  41. # use the symlinked ssh-auth-sock if available
  42. if [[ -f "$HOME/.ssh/ssh_auth_sock" ]]; then
  43. export SSH_AUTH_SOCK=$HOME/.ssh/ssh_auth_sock;
  44. fi
  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