[plt-scheme] Creating a symbolic link for OS X

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jul 17 01:28:37 EDT 2008

On Jul 17, Andrew Reilly wrote:
> On Tue, Jul 08, 2008 at 05:16:45PM -0700, Gregory Woodhouse wrote:
> > This is pretty much a minor annoyance, but with each new version I  
> > have to go through the same basic process to update my symbolic link / 
> > usr/local/plt
> > 
> > gregory-woodhouses-computer:/usr/local root# ln -s /Applications/PLT\  
> > Scheme\ v4.0.2 /usr/local/plt
> > gregory-woodhouses-computer:/usr/local root# exit
> > exit
> > ~:$ which mzscheme
> > /usr/local/plt/bin/mzscheme
> > ~:$
> > 
> > It would be nice if this could be automated.
> 
> Just as another alternative, I get around this by making my
> .profile put only the highest version into my $PATH:
> 
> PLT="$(/bin/ls -1d /Applications/PLT* | tail -1)"
> PATH=....other-paths...:$PLT/bin:...    export PATH

It's probably better to use

  PLT="$(/bin/ls -1dt /Applications/PLT* | head -1)"

so things won't break if there's a "PLT Scheme v4.0.10".


> Works a treat.  I just have to remember to restart terminal
> sessions after installing the latest version.

You could also make `mzscheme' itself be a script that does that every
time it runs.  You can even abstract this in a single script that can
invoke multiple programs.  Here's a quick example:

* add ~/bin to your path (it might already be there, I don't know the
  default OSX setup)

* Create a file called `runplt' there, with this contents:

    #!/bin/sh
    exec "$(/bin/ls -1dt /Applications/PLT* | head -1)/bin/$(basename "$0")"

* Now symlink as needed, for example:

    cd ~/bin
    ln -s runplt mzscheme
    ln -s runplt mred
    ln -s runplt plt-help
    ln -s runplt planet
    ...more for any commands you might need...

You can now use any of these commands which will default to the latest
path, and no terminal restart is need.

The only problem here is that this means that you pay the extra cost
of searching the recent directory on every execution.  You can use the
directory timestamp to "cache" the most recent directory, something
like this:

  #!/bin/sh
  if [ ! -e ~/.recent-plt ] || [ /Applications -nt ~/.recent-plt ]; then
    /bin/ls -1dt /Applications/PLT* | head -1 > ~/.recent-plt
  fi
  exec "$(cat ~/.recent-plt)/bin/$(basename "$0")"

(And you can use a similar script to create a symlink to the recent
PLT installation, and then run the script after every plt
installation.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.