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

Re: Re(4): environment var. not exported in macvim

Expand Messages
  • Benji Fisher
    ... Maybe I did not get it straight. If you are willing to help get ... I think that source and printenv work under tcsh ... ... I am not much interested in
    Message 1 of 12 , Feb 21, 2004
    • 0 Attachment
      On Sat, Feb 21, 2004 at 02:07:22PM +0100, Eckehard Berns wrote:
      > > I've found that this doesn't work; it produces a bunch of errors from
      > > tcsh when I try to run commands from within Vim:
      > >
      > > :!which aap
      > > tcsh: command whoami not found
      > > etc.
      > >
      > > The only way I can get the right PATH it seems is to launch Vim from
      > > Terminal.app.

      Maybe I did not get it straight. If you are willing to help get
      this to work, let us know what you get from the various stages:

      :echo $SHELL
      :set shell?
      :echo $PATH
      :echo system('echo $PATH')
      :echo system('source $HOME/.cshrc; printenv PATH')

      I think that source and printenv work under tcsh ...

      > MacOS X is a bit of a mess when using environment variables. Apple
      > suggests to use ~/.MacOSX/environment.plist (like Bob Ippolito pointed
      > out). I don't like that very much since you need to maintain that file
      > in addition to your shell startup files, and you can't use dynmic values
      > for environment variables. But at least that should solve the problem
      > for you.

      I am not much interested in this approach.

      > I don't think this problem can be solved in a distributed vimrc, btw.
      > You need to know which shell the user is running and then emulate
      > reading the propper startup files yourself or trick the shell in doing
      > so. Both ways need knowledge about that particular shell, and there are
      > a lot shells out there. I'm using zsh for example, which comes with
      > Panther. Thus any try guessing good values for PATH in tcsh and bash
      > only would have failed for me.

      IIRC, tcsh was the default on OS X 10.0 to 10.2, and bash is the
      default on OS X 10.3. If we can handle these two, we will satisfy most
      users. I am willing to deal with other shells as requests come in.

      Is there anything wrong with testing $SHELL and/or the 'shell'
      option? I wish that using a -l option to a shell would do it, but if
      necessary we can source the correct startup files "by hand."

      --Benji Fisher
    • Eckehard Berns
      ... Ok, maybe your right. We should at least try to help. ... A quick test based on your commands revealed that (sorry for line breaks) ... $ , , )
      Message 2 of 12 , Feb 21, 2004
      • 0 Attachment
        > IIRC, tcsh was the default on OS X 10.0 to 10.2, and bash is the
        > default on OS X 10.3. If we can handle these two, we will satisfy most
        > users. I am willing to deal with other shells as requests come in.

        Ok, maybe your right. We should at least try to help.

        > Is there anything wrong with testing $SHELL and/or the 'shell'
        > option? I wish that using a -l option to a shell would do it, but if
        > necessary we can source the correct startup files "by hand."

        A quick test based on your commands revealed that (sorry for line
        breaks)

        :let $PATH = substitute(system("echo echo '${PATH}' | $SHELL -l"),
        "\<C-J>$", "", "")

        worked for tcsh, bash and zsh (as well as sh and csh). The problem here
        is, though, that the user may not add any output to his/her startup
        files. Someone executing fortune for example in a startup file would
        end up in real trouble.

        Maybe something like (again meant to be put in one line)

        :let $PATH = substitute(system("echo echo VIMPATH'${PATH}' | $SHELL -l
        | grep ^VIMPATH | sed -e s/^VIMPATH//"), "\<C-J>$", "", "")

        would be more successful. My tests went fine.

        I'm not very experienced in scripting Vim. The grep and sed part might
        better be handled in Vim itself to save a few fork()s. There should be
        a test for the shell being one of the known shells also.

        --
        Eckehard Berns
      • Benji Fisher
        ... Very good! The part I did not get was passing something to the shell via stdin instead of with -c. Also, I would not have thought of the motd/fortune
        Message 3 of 12 , Feb 21, 2004
        • 0 Attachment
          On Sat, Feb 21, 2004 at 09:59:27PM +0100, Eckehard Berns wrote:
          >
          > A quick test based on your commands revealed that (sorry for line
          > breaks)
          >
          > :let $PATH = substitute(system("echo echo '${PATH}' | $SHELL -l"),
          > "\<C-J>$", "", "")
          >
          > worked for tcsh, bash and zsh (as well as sh and csh). The problem here
          > is, though, that the user may not add any output to his/her startup
          > files. Someone executing fortune for example in a startup file would
          > end up in real trouble.
          >
          > Maybe something like (again meant to be put in one line)
          >
          > :let $PATH = substitute(system("echo echo VIMPATH'${PATH}' | $SHELL -l
          > | grep ^VIMPATH | sed -e s/^VIMPATH//"), "\<C-J>$", "", "")
          >
          > would be more successful. My tests went fine.
          >
          > I'm not very experienced in scripting Vim. The grep and sed part might
          > better be handled in Vim itself to save a few fork()s. There should be
          > a test for the shell being one of the known shells also.

          Very good! The part I did not get was passing something to the
          shell via stdin instead of with -c. Also, I would not have thought of
          the motd/fortune problem. For testing, I added 'echo "Have a great
          day!"' to my .bash_profile .

          The following works for me. I think it is more readable to split
          it into two steps. I use a single matchstr() instead of
          grep/sed/substitute(), and "\n" instead of "\<C-J>":

          let s:path = system("echo echo VIMPATH'${PATH}' | $SHELL -l")
          let $PATH = matchstr(s:path, 'VIMPATH\zs.\{-}\ze\n')

          Just to be safe, we should wrap this in a comment and an if ... endif,
          like so:

          " Get the value of $PATH from a login shell.
          " If your shell is not on this list, it may be just because we have not
          " tested it. Try adding it to the list and see if it works. If so,
          " please post a note to the vim-mac list!
          if $SHELL =~ '^\(sh\|csh\|bash\|tcsh\|zsh\)$'
          ...
          endif

          Are there any further comments or improvements? If not, I will add
          this to the system vimrc's that I distribute. I do not expect any
          trouble with OS X 10.2.

          --Benji Fisher
        • Eckehard Berns
          ... That works fine for me. And it looks much cleaner the way you put it. ... I had to exchange the ^ for a / to make this work since $SHELL holds the complete
          Message 4 of 12 , Feb 21, 2004
          • 0 Attachment
            > let s:path = system("echo echo VIMPATH'${PATH}' | $SHELL -l")
            > let $PATH = matchstr(s:path, 'VIMPATH\zs.\{-}\ze\n')

            That works fine for me. And it looks much cleaner the way you put it.

            > if $SHELL =~ '^\(sh\|csh\|bash\|tcsh\|zsh\)$'

            I had to exchange the ^ for a / to make this work since $SHELL holds
            the complete path. But besides that I think this is a safe and quite
            complete solution to the PATH problem. I can't think of any more
            problems one might run into.

            --
            Eckehard Berns
          • Emily Jackson
            At 5:49 PM -0600 on Sunday, February 22, 2004, Eckehard Berns ... This works fine for me also (with tcsh). Emily
            Message 5 of 12 , Feb 22, 2004
            • 0 Attachment
              At 5:49 PM -0600 on Sunday, February 22, 2004, Eckehard Berns
              <ecki@...> wrote:

              >> let s:path = system("echo echo VIMPATH'${PATH}' | $SHELL -l")
              >> let $PATH = matchstr(s:path, 'VIMPATH\zs.\{-}\ze\n')
              >
              >That works fine for me. And it looks much cleaner the way you put it.
              >
              >> if $SHELL =~ '^\(sh\|csh\|bash\|tcsh\|zsh\)$'
              >
              >I had to exchange the ^ for a / to make this work since $SHELL holds
              >the complete path. But besides that I think this is a safe and quite
              >complete solution to the PATH problem. I can't think of any more
              >problems one might run into.

              This works fine for me also (with tcsh).

              Emily
            Your message has been successfully submitted and would be delivered to recipients shortly.