1
0

zshrc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. # Override agnosters prompt_dir
  16. # Using prompt_sorin's abbreviation
  17. prompt_dir() {
  18. local pwd="${PWD/#$HOME/~}"
  19. if [[ "$pwd" == (#m)[/~] ]]; then
  20. prompt="$MATCH"
  21. unset MATCH
  22. else
  23. prompt="${${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}//\%/%%}/${${pwd:t}//\%/%%}"
  24. fi
  25. prompt_segment blue $PRIMARY_FG " $prompt "
  26. }
  27. export PATH="$HOME/go/bin:$PATH"
  28. # random string function
  29. random-string()
  30. {
  31. LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | fold -w ${1:-32} | head -n 1
  32. }
  33. # make code printable with pandocs
  34. # printable-code filename.ext [forced-extension]
  35. printable-code()
  36. {
  37. body=`cat ${1}`
  38. [[ ${1} =~ "([^.]+).([^.]+)" ]] && name=$match[1] && ext=$match[2]
  39. ext=`test -n "${2}" && echo ${2} || echo $ext`
  40. doc="# ${1}\n\`\`\`$ext\n$body\n\`\`\`"
  41. oformat=`test -n "${3}" && echo ${3} || echo "pdf"`
  42. echo $doc | pandoc -o "$name.$oformat"
  43. }
  44. # mount a remote's ($1) host dir ($2) at $3/$2 or ~/mounts/$2 if $3 is not set
  45. mountremote () {
  46. # set the root mount dir
  47. mountroot="${3:-$HOME/mounts}";
  48. if [ -z "$2" ]; then
  49. mountpoint=$1-home
  50. else
  51. mountpoint=$1-`echo $2 | sed -E "s/\///g"`
  52. fi
  53. mkdir -p $mountroot/$mountpoint
  54. sshfs $1:$2 "$mountroot/$mountpoint" -o auto_cache,reconnect,volname=$mountpoint,no_readahead,noappledouble,nolocalcaches
  55. unset mountroot
  56. unset mountpoint
  57. }
  58. # check number of tmux sessions running on list of ssh hosts
  59. function tmux-num-sessions () {
  60. if (( $# == 0 )) then;
  61. echo usage: tmux-num-sessions ssh-host-1 ssh-host-2 ...
  62. fi
  63. hosts=$@
  64. for i; do
  65. sessions=$(ssh $i tmux ls 2>/dev/null)
  66. if (( $? )) then;
  67. echo $i: No sessions
  68. else
  69. echo $i: $(echo $sessions | wc -l) sessions
  70. fi
  71. done
  72. }
  73. # make the clipboard working on remote
  74. if [[ -n "$SSH_CLIENT" ]]; then
  75. SSH_IP=$(echo $SSH_CLIENT | awk '{print $1}')
  76. alias pbcopy="ssh $SSH_IP pbcopy"
  77. fi
  78. #
  79. # Aliases
  80. #
  81. # Git
  82. alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  83. 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"
  84. alias imgcat="~/.dotfiles/imgcat"
  85. # Utility
  86. alias rm="nocorrect rm"
  87. #
  88. # Python
  89. #
  90. # virtualenvwrapper
  91. if [ -f ~/virtualenvwrapper.sh ]; then
  92. source ~/virtualenvwrapper.sh
  93. export VIRTUAL_ENV_DISABLE_PROMT=yes
  94. fi
  95. if [[ -n "$ITERM_INTEGRATION" && -f ~/.iterm2_shell_integration.zsh ]]; then
  96. test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
  97. fi
  98. # a new attempt to forward ssh sockets to tmux
  99. if [[ -n "$SSH_AUTH_SOCK" ]]; then
  100. # based on/using http://stackoverflow.com/questions/21378569 and
  101. # https://gist.github.com/martijnvermaat/8070533
  102. # Fix SSH auth socket location so agent forwarding works with tmux
  103. if [[ -z "$TMUX" ]] ; then
  104. ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
  105. else
  106. export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
  107. fi
  108. fi
  109. # taskwarrior setup, stolen from https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/taskwarrior/taskwarrior.plugin.zsh
  110. zstyle ':completion:*:*:task:*' verbose yes
  111. zstyle ':completion:*:*:task:*:descriptions' format '%U%B%d%b%u'
  112. zstyle ':completion:*:*:task:*' group-name ''
  113. alias t=task
  114. compdef _task t=task