~ubuntu-branches/ubuntu/utopic/rbenv/utopic

« back to all changes in this revision

Viewing changes to libexec/rbenv-init

  • Committer: Package Import Robot
  • Author(s): Antonio Terceiro
  • Date: 2011-09-24 12:27:44 UTC
  • Revision ID: package-import@ubuntu.com-20110924122744-gpszt0huloxxzu6f
Tags: upstream-0.1.2+git20100922
ImportĀ upstreamĀ versionĀ 0.1.2+git20100922

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
set -e
 
3
[ -n "$RBENV_DEBUG" ] && set -x
 
4
 
 
5
print=""
 
6
if [ "$1" = "-" ]; then
 
7
  print=1
 
8
  shift
 
9
fi
 
10
 
 
11
shell="$1"
 
12
if [ -z "$shell" ]; then
 
13
  shell="$(basename "$SHELL")"
 
14
fi
 
15
 
 
16
resolve_link() {
 
17
  $(type -p greadlink readlink | head -1) $1
 
18
}
 
19
 
 
20
abs_dirname() {
 
21
  local cwd="$(pwd)"
 
22
  local path="$1"
 
23
 
 
24
  while [ -n "$path" ]; do
 
25
    cd "${path%/*}"
 
26
    local name="${path##*/}"
 
27
    path="$(resolve_link "$name" || true)"
 
28
  done
 
29
 
 
30
  pwd
 
31
  cd "$cwd"
 
32
}
 
33
 
 
34
root="$(abs_dirname "$0")/.."
 
35
 
 
36
if [ -z "$print" ]; then
 
37
  case "$shell" in
 
38
  bash )
 
39
    profile='~/.bash_profile'
 
40
    ;;
 
41
  zsh )
 
42
    profile='~/.zshrc'
 
43
    ;;
 
44
  * )
 
45
    profile='your profile'
 
46
    ;;
 
47
  esac
 
48
 
 
49
  { echo "# Load rbenv automatically by adding"
 
50
    echo "# the following to ${profile}:"
 
51
    echo
 
52
    echo 'eval "$(rbenv init -)"'
 
53
    echo
 
54
  } >&2
 
55
 
 
56
  exit 1
 
57
fi
 
58
 
 
59
mkdir -p "${RBENV_ROOT}/"{shims,versions}
 
60
 
 
61
echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"'
 
62
 
 
63
case "$shell" in
 
64
bash | zsh )
 
65
  echo "source \"$root/completions/rbenv.${shell}\""
 
66
  ;;
 
67
esac
 
68
 
 
69
echo 'rbenv rehash 2>/dev/null'
 
70
 
 
71
commands=(`rbenv commands --sh`)
 
72
IFS="|"
 
73
cat <<EOS
 
74
function rbenv() {
 
75
  command="\$1"
 
76
  if [ "\$#" -gt 0 ]; then
 
77
    shift
 
78
  fi
 
79
 
 
80
  case "\$command" in
 
81
  ${commands[*]})
 
82
    eval \`rbenv "sh-\$command" "\$@"\`;;
 
83
  *)
 
84
    command rbenv "\$command" "\$@";;
 
85
  esac
 
86
}
 
87
EOS