init.zsh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #
  2. # Configures Ruby local installation, loads version managers, and defines
  3. # aliases.
  4. #
  5. # Authors:
  6. # Sorin Ionescu <sorin.ionescu@gmail.com>
  7. # Indrajit Raychaudhuri <irc@indrajit.com>
  8. #
  9. # Possible lookup locations for manually installed rbenv and rvm.
  10. local_rbenv_paths=({$RBENV_ROOT,{$XDG_CONFIG_HOME/,$HOME/.}rbenv}/bin/rbenv(N))
  11. local_rvm_paths=({$RVM_DIR,{$XDG_CONFIG_HOME/,$HOME/.}rvm}/scripts/rvm(N))
  12. # Load manually installed or package manager installed rbenv into the shell
  13. # session.
  14. if (( $#local_rbenv_paths || $+commands[rbenv] )); then
  15. # Ensure manually installed rbenv is added to path when present.
  16. [[ -s $local_rbenv_paths[1] ]] && path=($local_rbenv_paths[1]:h $path)
  17. eval "$(rbenv init - zsh)"
  18. # Load manually installed rvm into the shell session.
  19. elif (( $#local_rvm_paths )); then
  20. # Unset AUTO_NAME_DIRS since auto adding variable-stored paths to ~ list
  21. # conflicts with rvm.
  22. unsetopt AUTO_NAME_DIRS
  23. source "$local_rvm_paths[1]"
  24. # Load package manager installed chruby into the shell session.
  25. elif (( $+commands[chruby-exec] )); then
  26. if (( ! $+functions[chruby] )); then
  27. source "${commands[chruby-exec]:h:h}/share/chruby/chruby.sh"
  28. fi
  29. if zstyle -t ':prezto:module:ruby:chruby' auto-switch; then
  30. if (( ! $+functions[chruby_auto] )); then
  31. source "${commands[chruby-exec]:h:h}/share/chruby/auto.sh"
  32. fi
  33. # If a default ruby is set, switch to it.
  34. chruby_auto
  35. fi
  36. # Prepend local gems bin directories to PATH.
  37. else
  38. path=($HOME/.gem/ruby/*/bin(N) $path)
  39. fi
  40. unset local_rbenv
  41. # Return if requirements are not found.
  42. if (( ! $+commands[ruby] && ! $#functions[(i)r(benv|vm)] )); then
  43. return 1
  44. fi
  45. #
  46. # Aliases
  47. #
  48. if ! zstyle -t ':prezto:module:ruby:alias' skip; then
  49. # General
  50. alias rb='ruby'
  51. # Bundler
  52. if (( $+commands[bundle] )); then
  53. alias rbb='bundle'
  54. alias rbbc='bundle clean'
  55. alias rbbe='bundle exec'
  56. alias rbbi='bundle install --path vendor/bundle'
  57. alias rbbl='bundle list'
  58. alias rbbo='bundle open'
  59. alias rbbp='bundle package'
  60. alias rbbu='bundle update'
  61. alias rbbI='rbbi \
  62. && bundle package \
  63. && print .bundle >>! .gitignore \
  64. && print vendor/assets >>! .gitignore \
  65. && print vendor/bundle >>! .gitignore \
  66. && print vendor/cache >>! .gitignore'
  67. fi
  68. fi