From f4d85bdc9421f827c0b516c44fdd0e0f34b8239b Mon Sep 17 00:00:00 2001 From: Dan Kleine Date: Sat, 8 Nov 2025 22:25:58 +0100 Subject: [PATCH 1/8] =?UTF-8?q?[FEATURE]=20=E2=9C=A8=20Add=20command=20to?= =?UTF-8?q?=20list=20configured=20versions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add »list« command to list all PHP versions configured with symlinks in the designated folder. --- bin/php-version-pickup.sh | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bin/php-version-pickup.sh b/bin/php-version-pickup.sh index 62c2962..253cd25 100644 --- a/bin/php-version-pickup.sh +++ b/bin/php-version-pickup.sh @@ -21,6 +21,9 @@ function php-version-pickup { elif [[ $1 == "use" ]]; then php-version-pickup::command_use; return 0 + elif [[ $1 == "list" ]]; then + php-version-pickup::command_list; return 0 + else php-version-pickup::command_help; return 0 fi @@ -38,6 +41,7 @@ function php-version-pickup { echo "Usage:" echo "php-version-pickup set Store version number in a file" echo "php-version-pickup use Pick up version from environment variable or file" + echo "php-version-pickup list List configured PHP versions" echo "php-version-pickup --help Show help" echo "php-version-pickup --version Show version" } @@ -84,6 +88,44 @@ function php-version-pickup { echo "Now using PHP version $PHP_VERSION_USE" } + function php-version-pickup::command_list { + local PHP_VERSION_USED=$(php -v 2>/dev/null | grep -oP "^PHP \K[0-9]+\.[0-9]+(\.[0-9]+)?") + + if [ -n "$PHP_VERSION_USED" ]; then + echo "Currently using PHP version $PHP_VERSION_USED" + else + echo 'Error: Unable to detect the currently used PHP version.' + fi + + echo 'Detecting configured PHP versions…' + + local PHP_VERSION_PATH="/home/$USER/.php/versions" + + if [ -z "$(ls -A "$PHP_VERSION_PATH")" ]; then + echo 'No PHP versions configured yet' + return 1 + fi + + echo '.' + + # Collect subfolders, sorted by number + local PHP_VERSION_PATH_SUBFOLDERS + mapfile -t PHP_VERSION_PATH_SUBFOLDERS < <(printf "%s\n" "$PHP_VERSION_PATH"/* | sort -V -r) + + for PHP_VERSION_PATH_SUBFOLDER in "${PHP_VERSION_PATH_SUBFOLDERS[@]}"; do + local PHP_VERSION_BINARY_PATH="$PHP_VERSION_PATH_SUBFOLDER/bin/php" + + local PHP_VERSION_BINARY_SYMLINK_TARGET='' + if [ -L "$PHP_VERSION_BINARY_PATH" ]; then + PHP_VERSION_BINARY_SYMLINK_TARGET=$(readlink "$PHP_VERSION_BINARY_PATH") + fi + + local PHP_VERSION=$("$PHP_VERSION_BINARY_PATH" -v 2>/dev/null | grep -oP "^PHP \K[0-9]+\.[0-9]+(\.[0-9]+)?") + + echo "├─ $(basename "$PHP_VERSION_PATH_SUBFOLDER") -> $PHP_VERSION_BINARY_SYMLINK_TARGET (Version $PHP_VERSION)" + done + } + # Helper methods function php-version-pickup::get_version { From 4ccd5c62a0f845326bf92620f91327e83d4ddbb1 Mon Sep 17 00:00:00 2001 From: Dan Kleine Date: Sat, 8 Nov 2025 22:32:42 +0100 Subject: [PATCH 2/8] =?UTF-8?q?[FEATURE]=20=E2=9C=A8=20Add=20command=20to?= =?UTF-8?q?=20list=20PHP=20releases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List active PHP releases (fetched from PHP.net) and show which local versions are EOL --- bin/php-version-pickup.sh | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/bin/php-version-pickup.sh b/bin/php-version-pickup.sh index 253cd25..66c7475 100644 --- a/bin/php-version-pickup.sh +++ b/bin/php-version-pickup.sh @@ -24,6 +24,9 @@ function php-version-pickup { elif [[ $1 == "list" ]]; then php-version-pickup::command_list; return 0 + elif [[ $1 == "releases" ]]; then + php-version-pickup::command_releases; return 0 + else php-version-pickup::command_help; return 0 fi @@ -42,6 +45,7 @@ function php-version-pickup { echo "php-version-pickup set Store version number in a file" echo "php-version-pickup use Pick up version from environment variable or file" echo "php-version-pickup list List configured PHP versions" + echo "php-version-pickup releases Show PHP release information and EOL status" echo "php-version-pickup --help Show help" echo "php-version-pickup --version Show version" } @@ -126,6 +130,74 @@ function php-version-pickup { done } + function php-version-pickup::command_releases { + echo 'PHP Release Information' + echo '' + echo 'Fetching data from php.net…' + echo '' + + # Fetch release data from php.net + local RELEASES_JSON=$(curl -s "https://www.php.net/releases/index.php?json" 2>/dev/null) + + if [ -z "$RELEASES_JSON" ]; then + echo 'Error: Failed to fetch release information' + return 1 + fi + + echo 'Active PHP Versions:' + echo "$RELEASES_JSON" | grep -oP '"[0-9]+\.[0-9]+"' | sort -u -V -r | while read -r VERSION_QUOTED; do + local VERSION=$(echo "$VERSION_QUOTED" | tr -d '"') + + # Get version details from JSON + local VERSION_DATA=$(echo "$RELEASES_JSON" | grep -A 10 "\"$VERSION\"") + + if [ -n "$VERSION_DATA" ]; then + local ANNOUNCEMENT=$(echo "$VERSION_DATA" | grep -oP '"announcement":.*?"date":"([^"]+)"' | head -1 | grep -oP '[0-9]{2} [A-Z][a-z]+ [0-9]{4}') + echo -e "├─ \033[32m●\033[0m PHP $VERSION" + if [ -n "$ANNOUNCEMENT" ]; then + echo "│ Latest release: $ANNOUNCEMENT" + fi + fi + done + + echo '' + echo 'Your Linked Versions:' + + local PHP_VERSION_PATH="/home/$USER/.php/versions" + local FOUND_LINKED=0 + + if [ -d "$PHP_VERSION_PATH" ] && [ -n "$(ls -A "$PHP_VERSION_PATH" 2>/dev/null)" ]; then + for VERSION_DIR in "$PHP_VERSION_PATH"/*; do + if [ -d "$VERSION_DIR" ]; then + local VERSION=$(basename "$VERSION_DIR") + local PHP_BIN="$VERSION_DIR/bin/php" + + if [ -f "$PHP_BIN" ]; then + local FULL_VERSION=$("$PHP_BIN" -v 2>/dev/null | grep -oP "^PHP \K[0-9]+\.[0-9]+(\.[0-9]+)?") + + # Check if version is in active list + local IS_ACTIVE=$(echo "$RELEASES_JSON" | grep -c "\"$VERSION\"") + + if [ "$IS_ACTIVE" -gt 0 ]; then + echo -e "├─ \033[32m✓\033[0m PHP $VERSION ($FULL_VERSION) - Active support" + else + echo -e "├─ \033[33m⚠\033[0m PHP $VERSION ($FULL_VERSION) - End of Life" + fi + + FOUND_LINKED=1 + fi + fi + done + fi + + if [ "$FOUND_LINKED" -eq 0 ]; then + echo '├─ No linked versions found' + fi + + echo '' + echo 'For more details visit: https://www.php.net/supported-versions.php' + } + # Helper methods function php-version-pickup::get_version { From 4867e7f556bfc9f07b6a92c4905d9703d4acbfc4 Mon Sep 17 00:00:00 2001 From: Dan Kleine Date: Sat, 8 Nov 2025 22:41:15 +0100 Subject: [PATCH 3/8] =?UTF-8?q?[FEATURE]=20=E2=9C=A8=20Add=20command=20to?= =?UTF-8?q?=20verify=20project=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check if project requirements are met and the expected PHP version is in use. --- bin/php-version-pickup.sh | 61 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/bin/php-version-pickup.sh b/bin/php-version-pickup.sh index 66c7475..227f19d 100644 --- a/bin/php-version-pickup.sh +++ b/bin/php-version-pickup.sh @@ -27,6 +27,9 @@ function php-version-pickup { elif [[ $1 == "releases" ]]; then php-version-pickup::command_releases; return 0 + elif [[ $1 == "check" ]]; then + php-version-pickup::command_check; return 0 + else php-version-pickup::command_help; return 0 fi @@ -42,10 +45,11 @@ function php-version-pickup { function php-version-pickup::command_help { php-version-pickup::command_version; echo "Usage:" - echo "php-version-pickup set Store version number in a file" - echo "php-version-pickup use Pick up version from environment variable or file" + echo "php-version-pickup set Store PHP version number in a file" + echo "php-version-pickup use Pick up PHP version from environment variable or file" echo "php-version-pickup list List configured PHP versions" echo "php-version-pickup releases Show PHP release information and EOL status" + echo "php-version-pickup check Verify project requirements and PHP version" echo "php-version-pickup --help Show help" echo "php-version-pickup --version Show version" } @@ -198,6 +202,52 @@ function php-version-pickup { echo 'For more details visit: https://www.php.net/supported-versions.php' } + function php-version-pickup::command_check { + local PHP_VERSION_PROJECT=$(php-version-pickup::get_project_version) + + if [ -z "$PHP_VERSION_PROJECT" ]; then + echo 'No .php-version file found in current directory' + return 1 + fi + + echo "Project requires PHP version $PHP_VERSION_PROJECT" + + local PHP_VERSION_BINARY_PATH="/home/$USER/.php/versions/$PHP_VERSION_PROJECT/bin/php" + + if [ -f "$PHP_VERSION_BINARY_PATH" ]; then + echo -e "├─ \033[32m✓\033[0m PHP $PHP_VERSION_PROJECT is linked and available" + + local PHP_VERSION_USED=$(php -v 2>/dev/null | grep -oP "^PHP \K[0-9]+\.[0-9]+") + if [ "$PHP_VERSION_USED" == "$PHP_VERSION_PROJECT" ]; then + echo -e "├─ \033[32m✓\033[0m PHP $PHP_VERSION_PROJECT is currently active" + else + echo -e "├─ \033[33m⚠\033[0m PHP $PHP_VERSION_PROJECT is not active" + echo " Run: php-version-pickup use" + fi + else + echo -e "├─ \033[31m✗\033[0m PHP $PHP_VERSION_PROJECT is not linked" + + # Check if version is installed but not linked + local SEARCH_PATHS=( + "/usr/bin" + "/usr/local/bin" + "/opt/homebrew/bin" + ) + + for SEARCH_PATH in "${SEARCH_PATHS[@]}"; do + for PHP_BIN in "$SEARCH_PATH"/php"$PHP_VERSION_PROJECT" "$SEARCH_PATH"/php; do + if [ -x "$PHP_BIN" ]; then + local VERSION=$("$PHP_BIN" -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" 2>/dev/null) + if [ "$VERSION" == "$PHP_VERSION_PROJECT" ]; then + echo "├─ Found PHP $PHP_VERSION_PROJECT at: $PHP_BIN" + break 2 + fi + fi + done + done + fi + } + # Helper methods function php-version-pickup::get_version { @@ -222,6 +272,13 @@ function php-version-pickup { fi } + function php-version-pickup::get_project_version { + # Get version from .php-version in current directory only + if [ -f ".php-version" ]; then + cat ".php-version" | tr -d '[:space:]' + fi + } + php-version-pickup::main "$@" # clean up sourced namespaced functions From 91b9921d69d7b803b99fa5155287a89a6cdc91da Mon Sep 17 00:00:00 2001 From: Dan Kleine Date: Sat, 8 Nov 2025 22:53:35 +0100 Subject: [PATCH 4/8] =?UTF-8?q?[FEATURE]=20=E2=9C=A8=20Add=20command=20to?= =?UTF-8?q?=20link=20versions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Finally! Adds a »link« command, which searches for several possible sources and offers to link them ina wizard like dialog. --- bin/php-version-pickup.sh | 121 +++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/bin/php-version-pickup.sh b/bin/php-version-pickup.sh index 227f19d..783d431 100644 --- a/bin/php-version-pickup.sh +++ b/bin/php-version-pickup.sh @@ -24,6 +24,9 @@ function php-version-pickup { elif [[ $1 == "list" ]]; then php-version-pickup::command_list; return 0 + elif [[ $1 == "link" ]]; then + php-version-pickup::command_link; return 0 + elif [[ $1 == "releases" ]]; then php-version-pickup::command_releases; return 0 @@ -48,6 +51,7 @@ function php-version-pickup { echo "php-version-pickup set Store PHP version number in a file" echo "php-version-pickup use Pick up PHP version from environment variable or file" echo "php-version-pickup list List configured PHP versions" + echo "php-version-pickup link Interactive wizard to link PHP versions" echo "php-version-pickup releases Show PHP release information and EOL status" echo "php-version-pickup check Verify project requirements and PHP version" echo "php-version-pickup --help Show help" @@ -134,6 +138,120 @@ function php-version-pickup { done } + function php-version-pickup::command_link { + echo 'PHP Version Link Wizard' + echo '' + + # Find installed versions + local -a PHP_VERSIONS=() + local -a PHP_PATHS=() + local INDEX=1 + + local SEARCH_PATHS=( + "/usr/bin" + "/usr/local/bin" + "/opt/homebrew/bin" + "/opt/php" + ) + + for SEARCH_PATH in "${SEARCH_PATHS[@]}"; do + if [ -d "$SEARCH_PATH" ]; then + for PHP_BIN in "$SEARCH_PATH"/php[0-9]* "$SEARCH_PATH"/php; do + if [ -x "$PHP_BIN" ] && [ ! -L "$PHP_BIN" ]; then + local VERSION=$("$PHP_BIN" -r "echo PHP_VERSION;" 2>/dev/null) + local VERSION_SHORT=$("$PHP_BIN" -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" 2>/dev/null) + + if [ -n "$VERSION" ]; then + # Check if not already linked + if [ ! -f "/home/$USER/.php/versions/$VERSION_SHORT/bin/php" ]; then + PHP_VERSIONS+=("$VERSION_SHORT") + PHP_PATHS+=("$PHP_BIN") + echo "├─ $INDEX) PHP $VERSION ($PHP_BIN)" + ((INDEX++)) + fi + fi + fi + done + fi + done + + if [ "$INDEX" -eq 1 ]; then + echo 'No unlinked PHP versions found' + return 0 + fi + + echo "├─ $INDEX) Custom path" + echo "├─ 0) Cancel" + echo '' + + read -r -p "Which version to link? [0-$INDEX]: " SELECTION + + if [ "$SELECTION" == "0" ]; then + echo 'Cancelled' + return 0 + fi + + local SELECTED_VERSION="" + local SELECTED_PATH="" + + if [ "$SELECTION" == "$INDEX" ]; then + # Custom path + read -r -p "Enter path to PHP binary: " SELECTED_PATH + if [ ! -x "$SELECTED_PATH" ]; then + echo "Error: Not a valid executable: $SELECTED_PATH" + return 1 + fi + SELECTED_VERSION=$("$SELECTED_PATH" -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" 2>/dev/null) + if [ -z "$SELECTED_VERSION" ]; then + echo 'Error: Could not determine PHP version from binary' + return 1 + fi + elif [ "$SELECTION" -ge 1 ] && [ "$SELECTION" -lt "$INDEX" ]; then + local ARRAY_INDEX=$((SELECTION - 1)) + SELECTED_VERSION="${PHP_VERSIONS[$ARRAY_INDEX]}" + SELECTED_PATH="${PHP_PATHS[$ARRAY_INDEX]}" + else + echo 'Invalid selection' + return 1 + fi + + echo '' + local VERSION_NAME="$SELECTED_VERSION" + + # Validate version name format + if ! [[ "$VERSION_NAME" =~ ^[0-9]+\.[0-9]+$ ]]; then + echo 'Error: Invalid version format. Use format: X.Y (e.g., 8.2)' + return 1 + fi + + local TARGET_DIR="/home/$USER/.php/versions/$VERSION_NAME/bin" + local TARGET_LINK="$TARGET_DIR/php" + + if [ -e "$TARGET_LINK" ]; then + read -r -p "Version $VERSION_NAME already exists. Overwrite? [y/N]: " CONFIRM + if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then + echo 'Cancelled' + return 0 + fi + rm -f "$TARGET_LINK" + fi + + mkdir -p "$TARGET_DIR" + ln -s "$SELECTED_PATH" "$TARGET_LINK" + + if [ $? -eq 0 ]; then + echo -e "\033[32m✓\033[0m PHP $VERSION_NAME successfully linked" + + local TEST_OUTPUT=$("$TARGET_LINK" --version 2>/dev/null | head -n 1) + if [ -n "$TEST_OUTPUT" ]; then + echo "Verified: $TEST_OUTPUT" + fi + else + echo 'Error: Failed to create symlink' + return 1 + fi + } + function php-version-pickup::command_releases { echo 'PHP Release Information' echo '' @@ -222,10 +340,11 @@ function php-version-pickup { echo -e "├─ \033[32m✓\033[0m PHP $PHP_VERSION_PROJECT is currently active" else echo -e "├─ \033[33m⚠\033[0m PHP $PHP_VERSION_PROJECT is not active" - echo " Run: php-version-pickup use" + echo "│ Run: php-version-pickup use" fi else echo -e "├─ \033[31m✗\033[0m PHP $PHP_VERSION_PROJECT is not linked" + echo "│ Run: php-version-pickup link" # Check if version is installed but not linked local SEARCH_PATHS=( From 7fb9e7b4d70be06ab41ebdc7aff367e0d44600bf Mon Sep 17 00:00:00 2001 From: Dan Kleine Date: Sat, 8 Nov 2025 22:57:58 +0100 Subject: [PATCH 5/8] =?UTF-8?q?[FEATURE]=20=E2=9C=A8=20List=20available=20?= =?UTF-8?q?and=20linked=20versions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous version showed linked versions only, now list available versions as well. --- bin/php-version-pickup.sh | 62 +++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/bin/php-version-pickup.sh b/bin/php-version-pickup.sh index 783d431..3d7dd23 100644 --- a/bin/php-version-pickup.sh +++ b/bin/php-version-pickup.sh @@ -50,7 +50,7 @@ function php-version-pickup { echo "Usage:" echo "php-version-pickup set Store PHP version number in a file" echo "php-version-pickup use Pick up PHP version from environment variable or file" - echo "php-version-pickup list List configured PHP versions" + echo "php-version-pickup list List available PHP versions" echo "php-version-pickup link Interactive wizard to link PHP versions" echo "php-version-pickup releases Show PHP release information and EOL status" echo "php-version-pickup check Verify project requirements and PHP version" @@ -102,20 +102,28 @@ function php-version-pickup { function php-version-pickup::command_list { local PHP_VERSION_USED=$(php -v 2>/dev/null | grep -oP "^PHP \K[0-9]+\.[0-9]+(\.[0-9]+)?") + local PHP_VERSION_PROJECT=$(php-version-pickup::get_project_version) - if [ -n "$PHP_VERSION_USED" ]; then + if [ -n "$PHP_VERSION_USED" ]; then echo "Currently using PHP version $PHP_VERSION_USED" else echo 'Error: Unable to detect the currently used PHP version.' fi + if [ -n "$PHP_VERSION_PROJECT" ]; then + echo -e "Project requires PHP version \033[36m$PHP_VERSION_PROJECT\033[0m (.php-version file found)" + fi + echo 'Detecting configured PHP versions…' local PHP_VERSION_PATH="/home/$USER/.php/versions" - if [ -z "$(ls -A "$PHP_VERSION_PATH")" ]; then + if [ -z "$(ls -A "$PHP_VERSION_PATH" 2>/dev/null)" ]; then echo 'No PHP versions configured yet' - return 1 + echo '' + echo 'Detecting installed but not linked PHP versions…' + php-version-pickup::find_installed_versions + return 0 fi echo '.' @@ -133,9 +141,19 @@ function php-version-pickup { fi local PHP_VERSION=$("$PHP_VERSION_BINARY_PATH" -v 2>/dev/null | grep -oP "^PHP \K[0-9]+\.[0-9]+(\.[0-9]+)?") + local PHP_VERSION_SHORT=$(echo "$PHP_VERSION" | grep -oP "^[0-9]+\.[0-9]+") - echo "├─ $(basename "$PHP_VERSION_PATH_SUBFOLDER") -> $PHP_VERSION_BINARY_SYMLINK_TARGET (Version $PHP_VERSION)" + local MARKER="├─" + if [ "$PHP_VERSION_SHORT" == "$PHP_VERSION_PROJECT" ]; then + MARKER="├─ \033[36m★\033[0m" + fi + + echo -e "$MARKER $(basename "$PHP_VERSION_PATH_SUBFOLDER") -> $PHP_VERSION_BINARY_SYMLINK_TARGET (Version $PHP_VERSION)" done + + echo '' + echo 'Detecting installed but not linked PHP versions…' + php-version-pickup::find_installed_versions } function php-version-pickup::command_link { @@ -398,6 +416,40 @@ function php-version-pickup { fi } + function php-version-pickup::find_installed_versions { + local SEARCH_PATHS=( + "/usr/bin" + "/usr/local/bin" + "/opt/homebrew/bin" + "/opt/php" + ) + + local FOUND_ANY=0 + + for SEARCH_PATH in "${SEARCH_PATHS[@]}"; do + if [ -d "$SEARCH_PATH" ]; then + for PHP_BIN in "$SEARCH_PATH"/php[0-9]* "$SEARCH_PATH"/php; do + if [ -x "$PHP_BIN" ] && [ ! -L "$PHP_BIN" ]; then + local VERSION=$("$PHP_BIN" -r "echo PHP_VERSION;" 2>/dev/null) + local VERSION_SHORT=$("$PHP_BIN" -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;" 2>/dev/null) + + if [ -n "$VERSION" ]; then + # Check if not already linked + if [ ! -f "/home/$USER/.php/versions/$VERSION_SHORT/bin/php" ]; then + echo "├─ $VERSION_SHORT at $PHP_BIN (not linked)" + FOUND_ANY=1 + fi + fi + fi + done + fi + done + + if [ "$FOUND_ANY" -eq 0 ]; then + echo 'No unlinked PHP versions found' + fi + } + php-version-pickup::main "$@" # clean up sourced namespaced functions From 5cc54eac85b38ae089b48d8d61104feb5433d390 Mon Sep 17 00:00:00 2001 From: Dan Kleine Date: Sat, 8 Nov 2025 22:55:49 +0100 Subject: [PATCH 6/8] =?UTF-8?q?[FEATURE]=20=F0=9F=92=84=20Add=20icon=20to?= =?UTF-8?q?=20set/use=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lets add an success icon to the the original set/use commands as well. --- bin/php-version-pickup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/php-version-pickup.sh b/bin/php-version-pickup.sh index 3d7dd23..23dac2c 100644 --- a/bin/php-version-pickup.sh +++ b/bin/php-version-pickup.sh @@ -53,7 +53,7 @@ function php-version-pickup { echo "php-version-pickup list List available PHP versions" echo "php-version-pickup link Interactive wizard to link PHP versions" echo "php-version-pickup releases Show PHP release information and EOL status" - echo "php-version-pickup check Verify project requirements and PHP version" + echo "php-version-pickup check Check if project requirements are met" echo "php-version-pickup --help Show help" echo "php-version-pickup --version Show version" } @@ -67,7 +67,7 @@ function php-version-pickup { # Store version number in file echo $PHP_VERSION_TO_SET > $(pwd)'/.php-version' - echo "Set version <$PHP_VERSION_TO_SET> in $(pwd)/.php-version" + echo -e "\033[32m✓\033[0m Set version <$PHP_VERSION_TO_SET> in $(pwd)/.php-version" } function php-version-pickup::command_use { @@ -97,7 +97,7 @@ function php-version-pickup { # Populate binary to $PATH export PATH="$PHP_VERSION_BINARY_PATH:$PATH" - echo "Now using PHP version $PHP_VERSION_USE" + echo -e "\033[32m✓\033[0m Now using PHP version <$PHP_VERSION_USE>" } function php-version-pickup::command_list { From 8c5fccda6c3413c0227520fbe03d7550089835e7 Mon Sep 17 00:00:00 2001 From: Dan Kleine Date: Sun, 9 Nov 2025 00:52:55 +0100 Subject: [PATCH 7/8] =?UTF-8?q?[FEATURE]=20=F0=9F=93=9D=20Docs:=20Add=20ne?= =?UTF-8?q?w=20key=20features=20and=20examples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new features and a matching walkthrough --- README.md | 191 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 119 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index dac3017..31a47be 100644 --- a/README.md +++ b/README.md @@ -26,34 +26,32 @@ perfectly well with PHP, but does not want to store files nor support PHP versions installed by the OS package manager. That's why this script was created. -The file `.php-version` is already used by popular PHP packages like -[Symfony Server](https://symfony.com/doc/current/setup/symfony_server.html#selecting-a-different-php-version). - -**Key Features** - -- Set a PHP version for a shell session only (forget version in new shells, - don't mangle system defaults) -- [Pass the version to subscripts as well](https://pixelbrackets.de/notes/pass-php-version-to-subscripts-in-cli-calls) - (run Composer with the selected version, Composer passes the version to - other executed PHP scripts as well) -- Pick up the version from a `.php-version` file -- Support PHP versions installed via PPA -- Written in Bash, to pick versions before running PHP scripts -- Does not attempt to manage version used by the OS or webserver (Apache, Nginx) - -**Current limitations** *✨ Feel free to send a PR to resolve them✨* - -- Mayor PHP version numbers only (`7.3`, `7.4`, no `7.3.10`) -- No `latest` version etc. -- No installation of missing versions -- No automatic execution (`cd` hook) -- No display of locally available versions -- No display of remote available versions (all PHP version releases) +The script is intentionally lightweight and shell-first: +it makes no global OS changes, doesn’t touch the webserver, +and doesn’t install PHP automatically. Instead, it links existing binaries. +It keeps things conservative and CI-friendly with a simple symlink layout, +clear output, and proper exit codes. + +## Key Features + +- Set a PHP version for the current shell session only (no system-wide change; + forgotten in new shells, system defaults remain untouched) +- Pick up the PHP version from [nearest `.php-version` file](https://symfony.com/doc/current/setup/symfony_cli.html#selecting-php-version) + or persist it via `set` +- [Pass the version to subscripts](https://pixelbrackets.de/notes/pass-php-version-to-subscripts-in-cli-calls) + as well — e.g. run Composer with the selected version, + which propagates to executed PHP scripts +- List configured and in-use PHP versions +- Show official PHP releases from php.net and compare them to your local linked versions +- Verify a project’s required PHP version for local checks or CI pipelines +- Auto-detect installed PHP binaries and create the expected configuration layout interactively +- Supports PHP versions installed via PPA +- Written in Bash — no extra runtime, no OS or webserver interference ## Requirements -- PHP (the script picks up existing PHP versions, it runs without PHP however - as it is a shell script) +- Bash +- PHP (the script picks up existing PHP versions) ## Installation @@ -66,29 +64,28 @@ The file `.php-version` is already used by popular PHP packages like ```bash echo 'source $HOME/.php-version-pickup/bin/php-version-pickup.sh' >> $HOME/.bashrc ``` - *or* add the line manually to your `.bashrc` file - ```bash - source $HOME/.php-version-pickup/bin/php-version-pickup.sh # or your place of choice - ``` -- 🏗️ Install multiple PHP versions (build manually, use the great - [PPA by Ondřej Surý](https://launchpad.net/~ondrej/+archive/ubuntu/php), - or use a tool like [php-build](https://github.com/php-build/php-build) or - [homebrew-php](https://github.com/josegonzalez/homebrew-php)) -- Create symlinks pointing the PHP versions locally available - - This depends very much on the way you installed the multiple PHP versions. - The general structure of each symlink is - `$HOME/.php/versions//bin/php -> ` - - The following example assumes you installed three versions via Ondřejs PPA. - *Adapt this to your own setup*. - ```bash - mkdir -p $HOME/.php/versions/7.3/bin && ln -s /usr/bin/php7.3 $HOME/.php/versions/7.3/bin/php - mkdir -p $HOME/.php/versions/7.4/bin && ln -s /usr/bin/php7.4 $HOME/.php/versions/7.4/bin/php - mkdir -p $HOME/.php/versions/8.0/bin && ln -s /usr/bin/php8.0 $HOME/.php/versions/8.0/bin/php - ``` -- 💡 You may want to add an alias as shortcut command to your `.bashrc` like - `alias pvm="php-version-pickup"` +- Install multiple PHP versions on your system + (the script does not install PHP versions itself; you need to have them available) + - 🏗️ Build manually, use the great + [PPA by Ondřej Surý](https://launchpad.net/~ondrej/+archive/ubuntu/php), + or a tool like [php-build](https://github.com/php-build/php-build) or + [homebrew-php](https://github.com/josegonzalez/homebrew-php) +- Link the installed versions: The script uses symlinks to point to PHP binaries + already available on your system, as this depends heavily on how your PHP versions + were installed. + + You can set up these symlinks manually **or**, more conveniently, + use the `php-version-pickup link` command, which guides you interactively + through linking all detected PHP binaries. + - **If** you do it manually, then the script expects the following structure + for configured versions: + `$HOME/.php/versions//bin/php -> ` + + Example command to link PHP 8.4 installed via PPA: + ```bash + mkdir -p $HOME/.php/versions/8.4/bin && ln -s /usr/bin/php8.4 $HOME/.php/versions/8.4/bin/php + ``` +- Restart your shell or source your `.bashrc` again ## Source @@ -96,39 +93,89 @@ https://github.com/webit-de/php-version-pickup/ ## Usage -The script reads the version from a file. +- **`php-version-pickup set `** -**Create a version file in your project of choice** + Stores the given PHP version `` in a `.php-version` file in the current directory. -⚠ Right now only -[mayor PHP release numbers](https://www.php.net/supported-versions) are allowed, -which means something like `7.4` or `8.1` (not a specific version like `7.4.10`). + ⚠ Only + [mayor PHP release numbers](https://www.php.net/supported-versions) are allowed, + which means something like `8.1` or `8.4` (not a specific version like `8.1.10`). -Example to set PHP version 7.4 in a project: -```bash -php-version-pickup set 7.4 -``` +- **`php-version-pickup use`** + + Reads `PHP_VERSION` environment variable or nearest `.php-version` file (traversing up), + validates the major.minor format, and prepends the found version link + to `PATH` for the current shell session. + In short: activates the desired PHP version for the current shell session. + +- **`php-version-pickup list`** + + Shows the currently used PHP version, the linked versions and autodetected + installed but not linked binaries in common locations. + Useful to get a quick system overview. + +- **`php-version-pickup link`** + + Interactive wizard which scans common PHP binary paths and offers to create + the expected symlink layout under `~/.php/versions//bin/php`. + +- **`php-version-pickup releases`** + + Displays official active releases from PHP.net and compares them + to your linked versions. + +- **`php-version-pickup check`** -(This is the same as running `echo "7.4" > .php-version` manually). + Verifies if the required version of a project is active in the current shell. + Returns exit code `0` if requirements are met, non-zero otherwise. -**Pick up the version** +- **`php-version-pickup --help`** -Run `php-version-pickup use` in your directory to pick up the version number. -You should see a message telling you that a file was found and which version -is used in your shell session from now on. + Displays a summary of all available commands and their usage. -Run `php --version` to check the version. +- **`php-version-pickup --version`** -Now you can run PHP scripts, Composer, whatever with the set version. + Prints the scripts version. -🥏 Play around with the version file, open and close shells, run some -PHP scripts and make yourself comfortable with this simple version picker. +### Examples / Walkthrough -**Provide feedback** +#### Typical project setup -This script is a prototype and helped us in a very specific use case. Therefore, -some limitations exists (see [vision](#vision)). Feel free to send some -feedback or create a PR to enhance this script. +```bash +php-version-pickup link # auto-detect & link installed PHP binaries - run once for new versions + +cd /path/to/project +php --version # shows system default PHP version, e.g. PHP 8.4 +php-version-pickup set 8.3 +php-version-pickup use +php --version # shows PHP 8.3 now +``` + +#### Show configured vs installed vs official releases + +```bash +php-version-pickup list +php-version-pickup releases +``` + +#### Verify required PHP version + +```bash +php-version-pickup check # returns exit code 0 if active PHP version matches the version set in `.php-version` file +``` + +### Tips + +- `php-version-pickup list` is the first stop to inspect what is configured + and what the system actually provides. +- Use `php-version-pickup link` when you installed PHP versions via package manager + or other tools — it creates the consistent symlink layout the script expects. +- `php-version-pickup releases` helps identify EOL versions so you can proactively upgrade projects. +- ᯓ🏃🏻‍♀️‍➡️ The `php-version-pickup …` command may be a bit long to type each time. + You may want to add an optional alias as shortcut command to your `.bashrc` like + `alias pvm="php-version-pickup"` +- Play around with the version file, open and close shells, run some + PHP scripts and make yourself comfortable with this simple version picker. ## License @@ -138,8 +185,8 @@ The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.h ## Author -Dan Untenzu ( / [@pixelbrackets](https://github.com/pixelbrackets)) -for webit! Gesellschaft für neue Medien mbH (http://www.webit.de/) +Dan Kleine ([@pixelbrackets](https://pixelbrackets.de)) +for webit! Gesellschaft für neue Medien mbH (https://www.webit.de/) ## Changelog From e5c922e3f8763eda197917854f2a1d647cab2d57 Mon Sep 17 00:00:00 2001 From: Dan Kleine Date: Sat, 8 Nov 2025 23:08:32 +0100 Subject: [PATCH 8/8] =?UTF-8?q?[TASK]=20=F0=9F=94=96=20Set=20version=201.4?= =?UTF-8?q?.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This release adds several practical features aimed at development and CI: - List configured and in-use PHP versions (`php-version-pickup list`) - Fetch official PHP releases from php.net and compare them to your local linked versions (`php-version-pickup releases`) - Verify a project’s required PHP version for local checks or CI pipelines (`php-version-pickup check`) - Auto-detect installed PHP binaries and create the expected symlink layout interactively (`php-version-pickup link`) → No more manual symlink maintenance \o/ --- CHANGELOG.md | 10 +++++++++- bin/php-version-pickup.sh | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e92296..80b813f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Changelog -2022-03-21 Dan Untenzu +2025-11-10 Dan Kleine + + * 1.4.0 + * FEATURE Add command to verify project version + * FEATURE Add command to link versions + * FEATURE Add command to list PHP releases + * FEATURE Add command to available and linked versions + + 2022-03-21 Dan Untenzu * 1.3.0 * FEATURE Add command to set version number in file diff --git a/bin/php-version-pickup.sh b/bin/php-version-pickup.sh index 23dac2c..3fa086d 100644 --- a/bin/php-version-pickup.sh +++ b/bin/php-version-pickup.sh @@ -41,7 +41,7 @@ function php-version-pickup { # Commands function php-version-pickup::command_version { - version="1.3.0" + version="1.4.0" echo -e "php-version-pickup (PHP Version Pickup) \033[32m$version\033[0m" }