You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 regels
2.7 KiB

11 jaren geleden
13 jaren geleden
11 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
11 jaren geleden
11 jaren geleden
11 jaren geleden
13 jaren geleden
11 jaren geleden
11 jaren geleden
11 jaren geleden
  1. #!/usr/bin/env bash
  2. # Summary: Configure the shell environment for rbenv
  3. # Usage: eval "$(rbenv init - [--no-rehash] [<shell>])"
  4. set -e
  5. [ -n "$RBENV_DEBUG" ] && set -x
  6. print=""
  7. no_rehash=""
  8. for args in "$@"
  9. do
  10. if [ "$args" = "-" ]; then
  11. print=1
  12. shift
  13. fi
  14. if [ "$args" = "--no-rehash" ]; then
  15. no_rehash=1
  16. shift
  17. fi
  18. done
  19. shell="$1"
  20. if [ -z "$shell" ]; then
  21. shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
  22. shell="${shell##-}"
  23. shell="${shell%% *}"
  24. shell="$(basename "${shell:-$SHELL}")"
  25. fi
  26. READLINK=$(type -p greadlink readlink | head -1)
  27. if [ -z "$READLINK" ]; then
  28. echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2
  29. exit 1
  30. fi
  31. resolve_link() {
  32. $READLINK "$1"
  33. }
  34. abs_dirname() {
  35. local cwd="$(pwd)"
  36. local path="$1"
  37. while [ -n "$path" ]; do
  38. cd "${path%/*}"
  39. local name="${path##*/}"
  40. path="$(resolve_link "$name" || true)"
  41. done
  42. pwd
  43. cd "$cwd"
  44. }
  45. root="$(abs_dirname "$0")/.."
  46. if [ -z "$print" ]; then
  47. case "$shell" in
  48. bash )
  49. profile='~/.bash_profile'
  50. ;;
  51. zsh )
  52. profile='~/.zshrc'
  53. ;;
  54. ksh )
  55. profile='~/.profile'
  56. ;;
  57. fish )
  58. profile='~/.config/fish/config.fish'
  59. ;;
  60. * )
  61. profile='your profile'
  62. ;;
  63. esac
  64. { echo "# Load rbenv automatically by adding"
  65. echo "# the following to ${profile}:"
  66. echo
  67. case "$shell" in
  68. fish )
  69. echo 'status --is-interactive; and . (rbenv init -|psub)'
  70. ;;
  71. * )
  72. echo 'eval "$(rbenv init -)"'
  73. ;;
  74. esac
  75. echo
  76. } >&2
  77. exit 1
  78. fi
  79. mkdir -p "${RBENV_ROOT}/"{shims,versions}
  80. if [[ ":${PATH}:" != *:"${RBENV_ROOT}/shims":* ]]; then
  81. case "$shell" in
  82. fish )
  83. echo "setenv PATH '${RBENV_ROOT}/shims' \$PATH"
  84. ;;
  85. * )
  86. echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
  87. ;;
  88. esac
  89. fi
  90. case "$shell" in
  91. fish )
  92. echo "setenv RBENV_SHELL $shell"
  93. ;;
  94. * )
  95. echo "export RBENV_SHELL=$shell"
  96. ;;
  97. esac
  98. completion="${root}/completions/rbenv.${shell}"
  99. if [ -r "$completion" ]; then
  100. case "$shell" in
  101. fish ) echo ". '$completion'" ;;
  102. * ) echo "source '$completion'" ;;
  103. esac
  104. fi
  105. if [ -z "$no_rehash" ]; then
  106. echo 'rbenv rehash 2>/dev/null'
  107. fi
  108. commands=(`rbenv-commands --sh`)
  109. case "$shell" in
  110. fish )
  111. cat <<EOS
  112. function rbenv
  113. set command \$argv[1]
  114. set -e argv[1]
  115. switch "\$command"
  116. case ${commands[*]}
  117. eval (rbenv "sh-\$command" \$argv)
  118. case '*'
  119. command rbenv "\$command" \$argv
  120. end
  121. end
  122. EOS
  123. exit 0
  124. ;;
  125. ksh )
  126. cat <<EOS
  127. function rbenv {
  128. typeset command
  129. EOS
  130. ;;
  131. * )
  132. cat <<EOS
  133. rbenv() {
  134. local command
  135. EOS
  136. ;;
  137. esac
  138. IFS="|"
  139. cat <<EOS
  140. command="\$1"
  141. if [ "\$#" -gt 0 ]; then
  142. shift
  143. fi
  144. case "\$command" in
  145. ${commands[*]})
  146. eval "\`rbenv "sh-\$command" "\$@"\`";;
  147. *)
  148. command rbenv "\$command" "\$@";;
  149. esac
  150. }
  151. EOS