From ed8ea1100c16bdbfb1cd60393f5c7c6eebab3007 Mon Sep 17 00:00:00 2001 From: Christoph Hochstrasser Date: Wed, 17 Aug 2011 16:32:26 +0200 Subject: [PATCH] Added version-name command which returns the current Version without information where this was set --- scripts/exec.sh | 3 ++- scripts/phpenv.sh | 20 ++------------------ scripts/version-name.sh | 24 ++++++++++++++++++++++++ scripts/version.sh | 16 ++-------------- scripts/versions.sh | 25 ++++++------------------- 5 files changed, 36 insertions(+), 52 deletions(-) create mode 100755 scripts/version-name.sh diff --git a/scripts/exec.sh b/scripts/exec.sh index 645018d..a7a9a15 100755 --- a/scripts/exec.sh +++ b/scripts/exec.sh @@ -43,7 +43,8 @@ fi realpath="$PHPENV_ROOT/versions/$default/bin/$command" if [ ! -x "$realpath" ]; then - phpenv_fail "Command \"$command\" not found." + echo "Command \"$command\" not found." >&2 + exit 127 fi "$realpath" $@ diff --git a/scripts/phpenv.sh b/scripts/phpenv.sh index 92f0614..b616dc2 100755 --- a/scripts/phpenv.sh +++ b/scripts/phpenv.sh @@ -16,26 +16,10 @@ export PHPENV_ROOT=$HOME/.phpenv export PHPENV_SCRIPTS_DIR=$PHPENV_ROOT/scripts export PATH="$PHPENV_ROOT/bin:$PATH" -if [ ! -d "$PHPENV_ROOT/"{versions,bin} ]; then +if [ ! -d "$PHPENV_ROOT/bin" ] || [ ! -d "$PHPENV_ROOT/versions" ]; then mkdir -p "$PHPENV_ROOT/"{versions,bin} fi -function phpenv_fail { - if [ -z $2 ]; then - exit_code=1 - else - exit_code=$2 - fi - - echo "phpenv: [ERROR] $1" >&2 - exit $exit_code -} -export -f phpenv_fail - -function _phpenv_usage { - "$PHPENV_SCRIPTS_DIR/help.sh" "phpenv" -} - function phpenv { if [ -z $1 ]; then echo "phpenv: Argument \"command\" is missing." >&2 @@ -48,7 +32,7 @@ function phpenv { fi if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then - _phpenv_usage + "$PHPENV_SCRIPTS_DIR/help.sh" "phpenv" return 1 fi diff --git a/scripts/version-name.sh b/scripts/version-name.sh new file mode 100755 index 0000000..0e58e11 --- /dev/null +++ b/scripts/version-name.sh @@ -0,0 +1,24 @@ +#!/bin/bash +#/ + +version_source=$("$PHPENV_SCRIPTS_DIR/version-source.sh") + +if [ 0 -ne $? ]; then + echo "No Version set." >&2 + exit 1 +fi + +if [ "$version_source" = "PHPENV_VERSION" ]; then + version="$PHPENV_VERSION" +else + if [ -f "$version_source" ]; then + version=$(cat "$version_source") + fi +fi + +if [ -z "$version" ]; then + echo "phpenv: No Version is set." >&2 + exit 1 +fi + +echo "$version" diff --git a/scripts/version.sh b/scripts/version.sh index c78f54e..986e169 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -10,18 +10,6 @@ if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then fi version_source=$("$PHPENV_SCRIPTS_DIR/version-source.sh") +version_name=$("$PHPENV_SCRIPTS_DIR/version-name.sh") -if [ 0 -ne $? ]; then - echo "No Version set." >&2 - exit 1 -fi - -if [ "$version_source" = "PHPENV_VERSION" ]; then - version="$PHPENV_VERSION" -else - if [ -f "$version_source" ]; then - version=$(cat "$version_source") - fi -fi - -echo "$version (set by $version_source)" +echo "$version_name (set by $version_source)" diff --git a/scripts/versions.sh b/scripts/versions.sh index 42f2130..f5d0c9e 100755 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -9,29 +9,16 @@ if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then exit $? fi +enabled=$("$PHPENV_SCRIPTS_DIR/version-name.sh") version_source=$("$PHPENV_SCRIPTS_DIR/version-source.sh") -if [ 0 -ne $? ]; then - enabled= -fi - -if [ "$version_source" = "PHPENV_VERSION" ]; then - enabled="$PHPENV_VERSION" -else - if [ -f "$version_source" ]; then - enabled=$(cat "$version_source") - else - enabled= - fi -fi - -packages=$(ls -1 "$PHPENV_ROOT/versions") +versions=$(ls -1 "$PHPENV_ROOT/versions") -for package in $packages +for version in $versions do - if [ -n "$enabled" ] && [ "$enabled" = "$package" ]; then - echo "* $package (set by $version_source)" + if [ -n "$enabled" ] && [ "$enabled" = "$version" ]; then + echo "* $version (set by $version_source)" else - echo " $package" + echo " $version" fi done