From 1ed231cb21afe7619513379e46ec3fa83ad91154 Mon Sep 17 00:00:00 2001 From: Graham Ashton Date: Sat, 13 Aug 2011 07:50:23 +0100 Subject: [PATCH] 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