29 lines
905 B
Fish
29 lines
905 B
Fish
function sc
|
|
# Step 1: Extract PHP version constraint from composer.json
|
|
set constraint (jq -r '.require.php // empty' composer.json | grep -oP '\d+\.\d+')
|
|
|
|
if test -z "$constraint"
|
|
echo "No PHP version constraint found in composer.json"
|
|
return 1
|
|
end
|
|
|
|
# Step 2: Find matching PHP binaries using find
|
|
set match ""
|
|
for bin in (find /usr/bin -maxdepth 1 -type f -executable -regex '.*/php[0-9]+\.[0-9]+')
|
|
set version_output ($bin -v 2>/dev/null | head -n 1)
|
|
set php_version (echo $version_output | grep -oP '\d+\.\d+')
|
|
|
|
if test "$php_version" = "$constraint"
|
|
set match $bin
|
|
break
|
|
end
|
|
end
|
|
|
|
if test -z "$match"
|
|
echo "No installed PHP binary matches constraint $constraint"
|
|
return 1
|
|
end
|
|
|
|
# Step 3: Execute Symfony console with matched PHP binary
|
|
$match ./bin/console $argv
|
|
end |