From 7a0cde9a4e871983d0fee058ccfa3aa4c886502f Mon Sep 17 00:00:00 2001 From: Graham Ashton Date: Sat, 13 Aug 2011 07:34:15 +0100 Subject: [PATCH 1/2] Remove set- prefix from local and default commands. --- README.md | 12 ++++++------ completions/rbenv.bash | 2 +- libexec/rbenv-default | 12 ++++++++++++ libexec/rbenv-help | 12 ++++++------ libexec/rbenv-local | 12 ++++++++++++ libexec/rbenv-set-default | 12 ++---------- libexec/rbenv-set-local | 12 ++---------- 7 files changed, 41 insertions(+), 33 deletions(-) create mode 100755 libexec/rbenv-default create mode 100755 libexec/rbenv-local diff --git a/README.md b/README.md index 467bbe3f..4bb518b5 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,8 @@ tools that do one thing well. * [1 How It Works](#section_1) * [2 Installation](#section_2) * [3 Usage](#section_3) - * [3.1 set-default](#section_3.1) - * [3.2 set-local](#section_3.2) + * [3.1 default](#section_3.1) + * [3.2 local](#section_3.2) * [3.3 versions](#section_3.3) * [3.4 version](#section_3.4) * [3.5 rehash](#section_3.5) @@ -122,26 +122,26 @@ when installing a gem that provides a binary). Like `git`, the `rbenv` command delegates to subcommands based on its first argument. The most common subcommands are: -### 3.1 set-default +### 3.1 default Sets the default version of Ruby to be used in all shells by writing the version name to the `~/.rbenv/default` file. This version can be overridden by a per-project `.rbenv-version` file, or by setting the `RBENV_VERSION` environment variable. - $ rbenv set-default 1.9.2-p290 + $ rbenv default 1.9.2-p290 The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). -### 3.2 set-local +### 3.2 local Sets a local per-project Ruby version by writing the version name to an `.rbenv-version` file in the current directory. This version overrides the default, and can be overridden itself by setting the `RBENV_VERSION` environment variable. - $ rbenv set-local rbx-1.2.4 + $ rbenv local rbx-1.2.4 ### 3.3 versions diff --git a/completions/rbenv.bash b/completions/rbenv.bash index 0e8a383d..3ad2aa21 100644 --- a/completions/rbenv.bash +++ b/completions/rbenv.bash @@ -17,7 +17,7 @@ _rbenv() { local prev="${COMP_WORDS[COMP_CWORD-1]}" case "$prev" in - set-* | prefix ) + default | local | prefix ) _rbenv_versions ;; * ) diff --git a/libexec/rbenv-default b/libexec/rbenv-default new file mode 100755 index 00000000..4e616cf4 --- /dev/null +++ b/libexec/rbenv-default @@ -0,0 +1,12 @@ +#!/usr/bin/env bash -e + +RBENV_VERSION="$1" +if [ -z "$RBENV_VERSION" ]; then + echo "usage: rbenv default VERSION" >&2 + exit 1 +fi + +# Make sure the specified version is installed +rbenv-prefix "$RBENV_VERSION" >/dev/null + +echo "$RBENV_VERSION" > "${HOME}/.rbenv/default" diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 8820b200..ef8f1dfd 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -22,23 +22,23 @@ case "$1" in Some useful rbenv commands are: commands List all commands rehash Rehash rbenv shims (run this after installing binaries) - set-default Set the default Ruby version - set-local Set a local directory-specific Ruby version + default Set the default Ruby version + local Set a local directory-specific Ruby version version Show the current Ruby version versions List all Ruby versions known by rbenv See 'rbenv help ' for more information on a specific command. For more information, see: https://github.com/sstephenson/rbenv#readme" ;; -set-default) echo "usage: rbenv set-default +default) echo "usage: rbenv default Sets the default Ruby version. You can override the default at any time -by setting a directory-specific version with \`rbenv set-local' or by +by setting a directory-specific version with \`rbenv local' or by setting the RBENV_VERSION environment variable. $(print_set_version)" ;; -set-local) echo "usage: rbenv set-local +local) echo "usage: rbenv local Sets the local directory-specific Ruby version by writing the version name to a file named '.rbenv-version'. @@ -46,7 +46,7 @@ name to a file named '.rbenv-version'. When you run a Ruby command, rbenv will look for an '.rbenv-version' file in the current directory and each parent directory. If no such file is found in the tree, rbenv will use the default Ruby version -specified with \`rbenv set-default', or the version specified in the +specified with \`rbenv default', or the version specified in the RBENV_VERSION environment variable. $(print_set_version)" diff --git a/libexec/rbenv-local b/libexec/rbenv-local new file mode 100755 index 00000000..fc94ec2d --- /dev/null +++ b/libexec/rbenv-local @@ -0,0 +1,12 @@ +#!/usr/bin/env bash -e + +RBENV_VERSION="$1" +if [ -z "$RBENV_VERSION" ]; then + echo "usage: rbenv local VERSION" >&2 + exit 1 +fi + +# Make sure the specified version is installed +rbenv-prefix "$RBENV_VERSION" >/dev/null + +echo "$RBENV_VERSION" > .rbenv-version diff --git a/libexec/rbenv-set-default b/libexec/rbenv-set-default index ba6bbb5c..cff1eb09 100755 --- a/libexec/rbenv-set-default +++ b/libexec/rbenv-set-default @@ -1,13 +1,5 @@ #!/usr/bin/env bash set -e -RBENV_VERSION="$1" -if [ -z "$RBENV_VERSION" ]; then - echo "usage: rbenv set-default VERSION" >&2 - exit 1 -fi - -# Make sure the specified version is installed -rbenv-prefix "$RBENV_VERSION" >/dev/null - -echo "$RBENV_VERSION" > "${HOME}/.rbenv/default" +echo "set-default has been renamed to default" >&2 +rbenv-default "$@" diff --git a/libexec/rbenv-set-local b/libexec/rbenv-set-local index 7ce0fe2f..a93ec24e 100755 --- a/libexec/rbenv-set-local +++ b/libexec/rbenv-set-local @@ -1,13 +1,5 @@ #!/usr/bin/env bash set -e -RBENV_VERSION="$1" -if [ -z "$RBENV_VERSION" ]; then - echo "usage: rbenv set-local VERSION" >&2 - exit 1 -fi - -# Make sure the specified version is installed -rbenv-prefix "$RBENV_VERSION" >/dev/null - -echo "$RBENV_VERSION" > .rbenv-version +echo "set-local has been renamed to local" >&2 +rbenv-local "$@" From 1ed231cb21afe7619513379e46ec3fa83ad91154 Mon Sep 17 00:00:00 2001 From: Graham Ashton Date: Sat, 13 Aug 2011 07:50:23 +0100 Subject: [PATCH 2/2] Report default or local version. If no argument is passed to the default or local sub commands, report the currently configured version. --- README.md | 6 ++++++ libexec/rbenv-default | 18 +++++++++++------- libexec/rbenv-help | 4 ++-- libexec/rbenv-local | 17 +++++++++++------ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4bb518b5..9635b362 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,9 @@ overridden by a per-project `.rbenv-version` file, or by setting the The special version name `system` tells rbenv to use the system Ruby (detected by searching your `$PATH`). +When run without a version number the currently configured default +version is reported. + ### 3.2 local Sets a local per-project Ruby version by writing the version name to @@ -143,6 +146,9 @@ overrides the default, and can be overridden itself by setting the $ rbenv local rbx-1.2.4 +When run without a version number the currently configured local +version is reported. + ### 3.3 versions Lists all Ruby versions known to rbenv, and shows an asterisk next to diff --git a/libexec/rbenv-default b/libexec/rbenv-default index 4e616cf4..56f1276e 100755 --- a/libexec/rbenv-default +++ b/libexec/rbenv-default @@ -1,12 +1,16 @@ #!/usr/bin/env bash -e RBENV_VERSION="$1" +VERSION_FILE="${HOME}/.rbenv/default" if [ -z "$RBENV_VERSION" ]; then - echo "usage: rbenv default VERSION" >&2 - exit 1 + if [[ -e "$VERSION_FILE" ]]; then + cat "$VERSION_FILE" + else + echo "No default version configured - set with: rbenv default " + fi +else + # Make sure the specified version is installed + rbenv-prefix "$RBENV_VERSION" >/dev/null + + echo "$RBENV_VERSION" > "$VERSION_FILE" fi - -# Make sure the specified version is installed -rbenv-prefix "$RBENV_VERSION" >/dev/null - -echo "$RBENV_VERSION" > "${HOME}/.rbenv/default" diff --git a/libexec/rbenv-help b/libexec/rbenv-help index ef8f1dfd..4acb7dc6 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -22,8 +22,8 @@ case "$1" in Some useful rbenv commands are: commands List all commands rehash Rehash rbenv shims (run this after installing binaries) - default Set the default Ruby version - local Set a local directory-specific Ruby version + default Set or show the default Ruby version + local Set or show the local directory-specific Ruby version version Show the current Ruby version versions List all Ruby versions known by rbenv diff --git a/libexec/rbenv-local b/libexec/rbenv-local index fc94ec2d..cfc72067 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -1,12 +1,17 @@ #!/usr/bin/env bash -e RBENV_VERSION="$1" +VERSION_FILE=".rbenv-version" if [ -z "$RBENV_VERSION" ]; then - echo "usage: rbenv local VERSION" >&2 - exit 1 + if [[ -e "$VERSION_FILE" ]]; then + cat "$VERSION_FILE" + else + echo "No local version configured - set with: rbenv local " + fi +else + # Make sure the specified version is installed + rbenv-prefix "$RBENV_VERSION" >/dev/null + + echo "$RBENV_VERSION" > "$VERSION_FILE" fi -# Make sure the specified version is installed -rbenv-prefix "$RBENV_VERSION" >/dev/null - -echo "$RBENV_VERSION" > .rbenv-version