Setting exports in Fish Shell
Asked Answered
C

3

16

I have multiple versions of PHP installed, and for my normal development I always use PHP 5.5.x installed via homebrew.

In the fish shell

 which php & php --version
=> /usr/local/bin/php
=> PHP 5.5.8 (cli) (built: Jan 16 2014 15:58:25)

The path is correct.

My problem is that when I have to develop with Drupal I use MAMP as a bundled lamp stack, and MAMP has its own php version included. My problem is that when using Drush with Drupal I cannot set the PHP executable path as I normally would in bash. I only want drush to use the bundled PHP version/executable.

In bash I can do this:

# Set Drush root to MAMP PHP
export DRUSH_PHP=/Applications/MAMP/bin/php/php5.5.3/bin/php

But this wont work in fish-shell, I tried with this (no success):

fish config location: ~/.config/fish/config.fish

set -x DRUSH_PHP=/Applications/MAMP/bin/php/php5.5.3/bin/php

If I run the fishshell with drush statusi always get this:

 Drupal version         :  7.26
 Site URI               :  http://default
 Database driver        :  mysql
 Database username      :  root
 Database name          :  dev-db
 Default theme          :  garland
 Administration theme   :  garland
 PHP executable         :  /usr/local/bin/php
 PHP configuration      :  /usr/local/etc/php/5.5/php.ini
 PHP OS                 :  Darwin
 Drush version          :  6.2.0
 Drush configuration    :
 Drush alias files      :
 Drupal root            :  /Applications/MAMP/htdocs/Sandbox/dev
 Site path              :  sites/default
 File directory path    :  sites/default/files

And when I run the same command in bourne shell I get the correct settings:

  Drupal version                  :  7.26                                        
  Site URI                        :  http://default                              
  Database driver                 :  mysql                                       
  Database username               :  root                                        
  Database name                   :  dev-db                                      
  Database                        :  Connected                                   
  Drupal bootstrap                :  Successful                                  
  Drupal user                     :  Anonymous                                   
  Default theme                   :  bartik                                      
  Administration theme            :  seven                                       
  PHP executable                  :  /Applications/MAMP/bin/php/php5.5.3/bin/php 
  PHP configuration               :  /Applications/MAMP/bin/php/php5.5.3/conf/php.ini                                       
  PHP OS                          :  Darwin                                      
  Drush version                   :  6.2.0                                       
  Drush configuration             :                                              
  Drush alias files               :                                              
  Drupal root                     :  /Applications/MAMP/htdocs/Sandbox/dev       
  Site path                       :  sites/default                               
  File directory path             :  sites/default/files                         
  Temporary file directory path   :  /Applications/MAMP/tmp/php   

So, how to set the export path to the DRUSH_PHP in fish?

Cathar answered 7/2, 2014 at 9:56 Comment(0)
C
20

Derp.

The syntax was a little different, but I figured it out. Anyone having this issue, you can set an export as this:

set -x DRUSH_PHP /Applications/MAMP/bin/php/php5.5.3/bin/php

and drush gets the correct PHP exec path.

See the set documentation to understand how set works in Fish as opposed to other shells. Basically:

set variable value
Cathar answered 7/2, 2014 at 10:7 Comment(1)
How do I "export LIBVA_DRIVER_NAME=iHD" in such a way so that it remains even after I restart/shutdown?Vaughn
P
23

In case you want to emulate the export command in your fish shell, just create the following file:

~/.config/fish/functions/export.fish

function export
    if [ $argv ] 
        set var (echo $argv | cut -f1 -d=)
        set val (echo $argv | cut -f2 -d=)
        set -g -x $var $val
    else
        echo 'export var=value'
    end
end

Launch a new terminal and then run export from your fish shell as expected:

> export foo=123
> echo $foo
123
Prakrit answered 1/4, 2015 at 9:50 Comment(0)
C
20

Derp.

The syntax was a little different, but I figured it out. Anyone having this issue, you can set an export as this:

set -x DRUSH_PHP /Applications/MAMP/bin/php/php5.5.3/bin/php

and drush gets the correct PHP exec path.

See the set documentation to understand how set works in Fish as opposed to other shells. Basically:

set variable value
Cathar answered 7/2, 2014 at 10:7 Comment(1)
How do I "export LIBVA_DRIVER_NAME=iHD" in such a way so that it remains even after I restart/shutdown?Vaughn
U
2
set -Ux DRUSH_PHP /Applications/MAMP/bin/php/php5.5.3/bin/php

-U or --universal

Sets a universal variable. The variable will be immediately available to all the user’s fish instances on the machine, and will be persist across restarts of the shell.

-x or --export

Causes the specified shell variable to be exported to child processes (making it an “environment variable”).

Usm answered 29/3, 2023 at 15:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.