From b720934126436db5bf079f2113dd89a3999b460f Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Thu, 11 Feb 2016 13:41:52 -0500 Subject: [PATCH] allow modification of version via hooks The new internal version-munge command is used to modify the version when read from a version file or when specified on the command line via the shell, local, or global commands. The version stored in a version file is not modified. This allows the user to modify the version dependent upon the existing environment. For example, if the PLENV_ROOT directory is shared across multiple platforms with different OS's, hardware, or ABI's, one could modify the version at run-time to include a platform specific suffix, allowing a single version stored in a version file to accomodate multiple platforms. For example, if the hostname is used to distinguish the platform, e.g. on each host Perl was installed with % plenv install --as 5.22-$(hostname) 5.22 Then with the following hook: % cat ~/.plenv/plenv.d/version-munge/hostname.bash #!/bin/bash if [[ "$version" != --* ]]; then suffix=$(hostname) plenv-prefix "$version-$suffix" 1> /dev/null \ && version="$version-$suffix" fi Setting % plenv global 5.22 will set ~/.plenv/version to 5.22 and the hook will ensure that each host will see its own version. --- libexec/plenv-sh-shell | 2 ++ libexec/plenv-version-file-read | 6 +++++- libexec/plenv-version-file-write | 2 +- libexec/plenv-version-munge | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100755 libexec/plenv-version-munge diff --git a/libexec/plenv-sh-shell b/libexec/plenv-sh-shell index 671c3ce..a634dd8 100755 --- a/libexec/plenv-sh-shell +++ b/libexec/plenv-sh-shell @@ -27,6 +27,8 @@ version="$1" shell="${PLENV_SHELL:-$SHELL}" shell="${shell##*/}" +version=$(plenv-version-munge $version) + if [ -z "$version" ]; then if [ -z "$PLENV_VERSION" ]; then echo "plenv: no shell-specific version configured" >&2 diff --git a/libexec/plenv-version-file-read b/libexec/plenv-version-file-read index 1da55a5..2535a0e 100755 --- a/libexec/plenv-version-file-read +++ b/libexec/plenv-version-file-read @@ -3,5 +3,9 @@ # Reads the first non-whitespace word from the specified version file, # careful not to load it whole in case there's something crazy in it. if [ -e "$1" ]; then - command -p awk 'BEGIN {rc=1} NF > 0 { print $1 ; exit rc=0 } END { exit rc }' "$1" + + version=$(command -p awk 'BEGIN {rc=1} NF > 0 { print $1 ; exit rc=0 } END { exit rc }' "$1") + + plenv-version-munge "$version" + fi diff --git a/libexec/plenv-version-file-write b/libexec/plenv-version-file-write index b512e4b..8734775 100755 --- a/libexec/plenv-version-file-write +++ b/libexec/plenv-version-file-write @@ -13,7 +13,7 @@ if [ -z "$PLENV_VERSION" ] || [ -z "$PLENV_VERSION_FILE" ]; then fi # Make sure the specified version is installed. -plenv-prefix "$PLENV_VERSION" >/dev/null +plenv-prefix "$(plenv-version-munge \"$PLENV_VERSION\")" >/dev/null # Write the version out to disk. echo "$PLENV_VERSION" > "$PLENV_VERSION_FILE" diff --git a/libexec/plenv-version-munge b/libexec/plenv-version-munge new file mode 100755 index 0000000..1068f36 --- /dev/null +++ b/libexec/plenv-version-munge @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Summary: munge the passed Perl version using plugins + +version="$1" +if [ "$version" != '' ]; then + + OLDIFS="$IFS" + IFS=$'\n' scripts=(`plenv-hooks version-munge`) + IFS="$OLDIFS" + + for script in "${scripts[@]}"; do + source "$script" + done + +fi + +echo "$version"