Feature #388

gmtswitch modification

Added by Florian about 5 years ago. Updated about 5 years ago.

Status:FeedbackStart date:2013-10-04
Priority:NormalDue date:
Assignee:-% Done:


Target version:-


I'd like to remove this find from it:

find / -type d -name 'GMT[34].*' -print > $home/.gmtversions
  1. it could take hours to complete.
  2. searching network shares, which are common in universities and institutes, can even take days.
  3. it usually doesn't find anything when gmt is installed via a package manager on Linux/Mac.

Instead one could probe for the first gmt executable found in PATH:

GMT_BINARY=($(which gmt psxy))
if [ -n "$GMT_BINARY_DIR" ]; then
 dirname $GMT_BINARY_DIR > $home/.gmtversions


#1 Updated by Paul about 5 years ago

  • Status changed from New to Feedback

Does not work so well for GMT 4, since in my case (if GMT 4 is selected already):\

which gmt psxy

So it returns two since gmt and psxy are two separate things in gmt4.

I added some more options to gmtswitch: 1. skip the search and instead add the file manually, 2. Limit the search by specifying the top dir of the search (instead of /).

#2 Updated by Florian about 5 years ago

which gmt psxy

So it returns two since gmt and psxy are two separate things in gmt4.

Yes, that was the intention. which should return two commands if they both exist. They are stored in the array GMT_BINARY. And $GMT_BINARY returns the first element (gmt, if found, else psxy if found, else nothing). I could have written

GMT_BINARY_DIR=$(dirname ${GMT_BINARY[0]})

to make it clearer. But my suggested approach is flawed as well and useless if no gmt/psxy is in the PATH.

I noticed, the problem with gmtswitch is that it is a black box and nightmare for GMT/UNIX newbies who do not yet know too much about PATHs and symlinks. On the other hand gmtswitch is addressed to the more advanced users (considering its command line messages and manual). For example, newbies most certainly won't be able to install the latest gmt 4.x (why would this be necessary even for the advanced users?).

Newbies also do not know that gmtswitch will use find to traverse the FS tree to search for directories beginning with the case sensitive literal strings "GMT3.", "GMT4.", or "GMT5.". Chances are slim that the find will return anything even if gmt is installed somewhere on the system. So puzzlement and frustration arise when gmtswitch cannot locate gmt after hours of searching, whereas the advanced user already has his .gmtversions file and doesn't care about the find anyway. These are some of the reasons why I suggested simplifying gmtswitch by removing features that will work under special conditions only.

Since gmtswitch knows its own location, the simplest and most bulletproof solution would be to

RUNDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 
# create .gmtversions if it doesn't exist yet:
test -f ~/.gmtversions || echo $GMTBASE > ~/.gmtversions
and then instruct the user to manually add other versions (according to the steps in the manual).

Also available in: Atom PDF