2

I want to update my fish shell to use the current version of php from MAMP (which ever version is currently in use).

I found an excellent article on how to do this in bash, but I can't seem to work out how to achieve this in fish?

The article is: How to override the path of PHP to use the MAMP path?

Specifically:

# Use MAMP version of PHP
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH

How do you achieve this in fish? Fish wants to export PHP_VERSION as a string.

And also using these commmand alias's to use current version of MySQL

# Export MAMP MySQL executables as functions
# Makes them usable from within shell scripts (unlike an alias)
mysql() {
    /Applications/MAMP/Library/bin/mysql "$@"
}
mysqladmin() {
    /Applications/MAMP/Library/bin/mysqladmin "$@"
}
export -f mysql
export -f mysqladmin

I have tried to figure out the various pieces of this, but having limited understanding of commandline makes it difficult to know what to 'search' for.

Appreciate any help!

Community
  • 1
  • 1
JP Charrier
  • 63
  • 1
  • 9

1 Answers1

7

Setting PATH is covered in the fish tutorial.

Ordinarily you could simply modify fish_user_paths, but since you want the path to be dynamically determined on every launch, it's simpler to set PATH directly. A straightforward translation:

set PHP_VERSION (ls /Applications/MAMP/bin/php/ | sort -n | tail -1)
set -x PATH /Applications/MAMP/bin/php/$PHP_VERSION/bin $PATH

You would put that in ~/.config/fish/fish.config

Regarding "exporting functions", this was always a suspicious idea (it was the source of that terrible bash security hole) and is not something that fish supports. You should just instead arrange for /Applications/MAMP/Library/bin/mysql to be in PATH, so that child scripts can find your executables. Just like before:

set -x PATH /Applications/MAMP/Library/bin/ $PATH
ridiculous_fish
  • 17,273
  • 1
  • 54
  • 61
  • Thanks that's helpful, but it's still not working. It still only shows the the highest version, not the current one. Is it actually possible to detect which version MAMP is currently using and then set that in $PATH (dynamically) – JP Charrier Aug 04 '15 at 12:09
  • I should restructure my question and repost I think. First - How to determine the version of PHP mamp is using dynamically. Because running `ls /Applications/MAMP/bin/php/ | sort -n | tail -1` returns `total 0` and secondly then how to dynamically set that. – JP Charrier Aug 04 '15 at 12:11
  • add this to my fish.config file successfully change my command line php version, thanks! – Ronnie Sep 23 '22 at 22:45