Skip to content

Commit

Permalink
Added version-name command which returns the current Version without …
Browse files Browse the repository at this point in the history
…information where this was set
  • Loading branch information
CHH committed Aug 17, 2011
1 parent 95b8a6f commit ed8ea11
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 52 deletions.
3 changes: 2 additions & 1 deletion scripts/exec.sh
Expand Up @@ -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" $@
20 changes: 2 additions & 18 deletions scripts/phpenv.sh
Expand Up @@ -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
Expand All @@ -48,7 +32,7 @@ function phpenv {
fi

if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
_phpenv_usage
"$PHPENV_SCRIPTS_DIR/help.sh" "phpenv"
return 1
fi

Expand Down
24 changes: 24 additions & 0 deletions 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"
16 changes: 2 additions & 14 deletions scripts/version.sh
Expand Up @@ -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)"
25 changes: 6 additions & 19 deletions scripts/versions.sh
Expand Up @@ -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

0 comments on commit ed8ea11

Please sign in to comment.