Richard Bucker

fishshell and the makefile

Posted at — Mar 24, 2015

I had a number of problems getting my makefile to work with fishshell. The first challenge was making GOPATH make sense but that was cleared up with an article by Andrew Gerand. Basically it came down to two tips. (1) more than one item in the GOPATH is ok (2) the first item in the set is the vendor folder. Voila.But if you are like me and you like fishshell then the config file is bothering you. So let start at the beginning.I have a simple Makefile with one sub-command:env:    @echo “GOPATH=$(GOPATH)"In my fish config file (like .profile or .bashrc) I have the following:set -g GOPATH $HOME/gorepo $HOMEThe -g indicates that I’m setting the GOPATH environment variable in the “global” space. Meaning this session or terminal window. Notice that I’m setting the values $HOME/gorepo and $HOME to the GOPATH variable.But something interesting happens when I execute the command make env. For some reason I get the following output:GOPATH=/Users/rbucker/gorepoand I know this is the wrong value.After re-reading the man page for the set command I discovered the ‘-x’ option.  This tells fish to copy the environment variable to the child processes. This is an odd behavior because it was not obvious that the options could be commingled and the documentation never suggested it.  Just that the -g should have been enough.Anyway, adding the -x to the -g and re-running my make env command and I got the right results.This is good news for me as I was getting ready to cut bait.