Loading ...
Sorry, an error occurred while loading the content.

symlinked mvim script can't find original (with solution)

Expand Messages
  • Lance E Sloan
    The problem: If MacVim is not installed in one of the common directories and the mvim script called from the shell prompt is actually a symbolic link
    Message 1 of 1 , Aug 23, 2013
    • 0 Attachment
      The problem: If MacVim is not installed in one of the common directories and the mvim script called from the shell prompt is actually a symbolic link (symlink) to the original mvim script, the script will probably fail with the error message:

      Sorry, cannot find MacVim.app. Try setting the VIM_APP_DIR
      environment variable to the directory containing MacVim.app.

      As the error message says, one could set the VIM_APP_DIR environment variable to resolve this, but I've noticed a small change to the mvim script that can eliminate the need for that variable in many cases.

      The background: I don't like to install non-Apple applications in /Applications if I can avoid it. I like to install them in /Local/Applications instead. When I installed MacVim, I did that. The app and the mvim script are in a MacVim folder, so that their full paths are:

      /Local/Applications/MacVim/MacVim.app
      /Local/Applications/MacVim/mvim

      I have a "bin" directory in my home directory and $HOME/bin is in my path. To add the mvim script to my path, I created a symlink to the mvim script in its installation directory. That is:

      $HOME/bin/mvim -> /Local/Applications/MacVim/mvim

      When I call the mvim script, I get the error mentioned above because the correct directory is not returned from this link of the mvim script:

      myDir="`dirname "$0"`"

      myDir ends up with the value of $HOME/bin, which is not where MacVim.app is installed. A possible solution would be to also add a symlink to MacVim.app in $HOME/bin, but that doesn't feel "right".

      My solution: Replace the setting of myDir in the mvim script with this:

      myDir=$(dirname "$(readlink "$0")")
      if [ -z "$myDir" ]
      then
      myDir="`dirname "$0"`"
      fi

      This uses the "readlink" utility to try to read the original file to which the current script name links. If the result is an empty string (probably because the script name probably wasn't a symlink), fall back to using the current script name, as before

      This is a good solution, because if these additional lines were added to the distributed mvim script, it would eliminate the need for more users to edit the script or set the VIM_APP_DIR environment variable.

      I thought of posting this as a bug to the MacVim issue tracker, but since it feels more like an enhancement or feature request, I followed the instructions to post about it here first.

      --
      --
      You received this message from the "vim_mac" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_mac" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_mac+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    Your message has been successfully submitted and would be delivered to recipients shortly.