-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not work with fish 3.1.0 #75
Comments
I'm also curious about this because the readme was changed at the start of 2019 to say In case anyone stumbles across this I worked around it by using function php-version
bass source (brew --prefix php-version)/php-version.sh ';' php-version $argv
end |
I've written an implementation in native ###
# Switches PHP versions by modifying the $PATH variable
# Based on https://github.com/wilmoore/php-version
# NOTE: Unlike the original, this fish implementation
# only supports versions installed via Homebrew
#
# Globals:
# $PATH, $MANPATH
# Arguments:
# $version string PHP version (e.g. `7`, `7.4` or `7.4.4`);
# if not given, all available versions are printed
# Returns:
# None
###
function php-version
# ensure that Homebrew is installed
if test -z (command -v brew)
echo -e "\033[31mError:\033[0m Homebrew is not available." >&2
return 1
end
# make a list of all installed PHP versions
set directories (find (brew --prefix)/opt -maxdepth 1 -name 'php@*') (brew --prefix)/opt/php
# ensure that we have found at least one PHP version
if test -z "$directories"
echo -e "\033[31mError:\033[0m No PHP versions were detected," >&2
echo -e " install some with \033[34mbrew install php@*\033[0m." >&2
return 1
end
# make a list of actual installed PHP versions
set versions
for d in $directories
set versions $versions ($d/bin/php-config --version)
end
if test -z "$argv[1]"
# no argument, print all available versions
# determine the current version
set currentVersion (php-config --version)
# print all versions and highlight the current one
for v in $versions
if test "$v" = "$currentVersion"
echo -e "\033[7m* $v\033[0m"
else
echo " $v"
end
end
else if test "$argv[1]" = "complete"
# output available versions for the completion
echo $versions
else
# switch to the specified PHP version
# find the first version (starting from the latest one)
# that starts with the specified version string
set selectedVersion
set selectedDirectory
for i in (seq (count $directories) 1)
if string match -q "$argv[1]*" "$versions[$i]"
set selectedVersion "$versions[$i]"
set selectedDirectory "$directories[$i]"
break
end
end
# ensure that we have found a version
if test -z $selectedVersion
echo -e "\033[31mError:\033[0m Could not find a matching PHP version for \033[34m$argv[1]\033[0m." >&2
echo -e " (Options: \033[34m$versions\033[0m)" >&2
return 1
end
echo -e "Switching to PHP \033[34m$selectedVersion\033[0m..."
# switch to the new version
set -x PATH $selectedDirectory/bin $selectedDirectory/sbin $PATH
set -x MANPATH $selectedDirectory/share/man $MANPATH
end
end Matching set options (php-version complete)
if test -n options
complete -c php-version -a "$options"
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for creating this simple and useful tool. I have been using it for a few years and now wanted to switch one machine to the
fish
shell, which is supported according to theREADME
.Is this an issue in my setup or is
fish
currently not supported byphp-version
?Error:
Debug information:
The text was updated successfully, but these errors were encountered: