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

Re: Shelling out to cygwin bash from Windows vim

Expand Messages
  • AndyHancock
    ... I assume that taking out c:/cygwin would take care of the situations in which cygwin is installed elsewhere. Interesting that let
    Message 1 of 9 , Sep 3, 2012
    • 0 Attachment
      On Sep 2, 1:40 am, Gary Johnson <garyj...@...> wrote:
      > On 2012-09-01, AndyHancock wrote:
      > >          let &shell='c:\cygwin\bin\bash.exe ' .
      > >             \ --rcfile c:/cygwin/home/' . $USERNAME . '/.bashrc -i'
      >
      > Windows has to understand the path to the shell executable, but the
      > argument to --rcfile is interpreted by Cygwin's bash, which only
      > officially supports POSIX paths, so it should be something like
      > this:
      >
      >     /home/$USERNAME/.bashrc

      I assume that taking out c:/cygwin would take care of the situations
      in which cygwin is installed elsewhere.

      Interesting that

      let &shell='c:\cygwin\bin\bash.exe
      \ --rcfile /home/'.$USERNAME.'/.bashrc -i'

      works but

      let &shell='c:\cygwin\bin\bash.exe
      \ --rcfile /home/$USERNAME/.bashrc -i'

      does not. If I do

      !!echo $USERNAME

      bash returns the correct username comes back. That would seem to
      indicate that the 2nd shell setting above should work too. A mystery
      for another day...

      --
      You received this message from the "vim_use" 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
    • Linda W
      ... Wow... that looks complicated. Why don t you just set SHELL=C:/Bin/Bash.exe I have my cygwin in C:/ In my system environment vars (controlpanel- system-
      Message 2 of 9 , Sep 6, 2012
      • 0 Attachment
        AndyHancock wrote:
        > This problem dogged me for many years, and I finally hunkered down to
        > chase it down.
        >
        > Here is the solution that I found works for me:
        >
        > "set shell=c:\cygwin\bin\bash.exe\ -i
        > "Won't always find ~/.bashrc cuz depending on how vim is launched,
        > "~ doesn't always resolve to c:/cygwin/home/$USERNAME
        > "let &shell='c:\cygwin\bin\bash.exe\ --rcfile c:\cygwin\home\' .
        > " \ $USERNAME . '\.bashrc'
        > "Backslashes are hated by bash. Also needs -i to ensure bash is
        > "interactive so that .bashrc is sourced
        > let &shell='c:\cygwin\bin\bash.exe --rcfile c:/cygwin/home/' .
        > \ $USERNAME . '/.bashrc -i'
        > " Depending on how vim is launched, c:/cygwin/home/$USERNAME
        > " will sometimes be equivalent to ~. If so, then it will be
        > " replaced by ~ in &shell.
        >
        > Thanks to all those who helped on the unix, bash, cygwin, and vim
        > forums.
        >
        >
        Wow... that looks complicated.

        Why don't you just set
        SHELL=C:/Bin/Bash.exe

        I have my cygwin in C:/

        In my system environment vars (controlpanel->system->
        advanced system settings(system properties)->Advanced->
        Environment variables->System Variables,
        I have:

        DISPLAY=:0
        CYGWIN=nodosfilewarning winsymlinks export
        PATH=C:\prog64\vim;%SystemRoot%\system32;%SystemRoot%;C:\bin;[other
        stuff]...
        SHELL=C:/Bin/Bash.exe

        Bash starts and runs it's RC vars, which pick up my home.. and
        that runs my .bashrc.

        One of the aliases I have in my bash startup files
        for gvim is "setsid gvim"

        That allows gvim to run in the background...

        Would that work for you?

        I let bash & cygwin figure out my userid and home ..



        --
        You received this message from the "vim_use" 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
      • AndyHancock
        ... I think it looks complicated at first glance, but it s only one vim command. The rest is either comments explaining the one command, or commented-out
        Message 3 of 9 , Sep 15, 2012
        • 0 Attachment
          On Sep 7, 1:10 am, Linda W <v...@...> wrote:
          > AndyHancock wrote:
          >> This problem dogged me for many years, and I finally hunkered down
          >> to chase it down.
          >>
          >> Here is the solution that I found works for me:
          >>
          >> "set shell=c:\cygwin\bin\bash.exe\ -i
          >> "Won't always find ~/.bashrc cuz depending on how vim is
          >> "launched, ~ doesn't always resolve to c:/cygwin/home/$USERNAME
          >> "let &shell='c:\cygwin\bin\bash.exe\ --rcfile c:\cygwin\home\' .
          >> " \ $USERNAME . '\.bashrc'
          >> "Backslashes are hated by bash. Also needs -i to ensure
          >> "bash is interactive so that .bashrc is sourced
          >> let &shell='c:\cygwin\bin\bash.exe --rcfile c:/cygwin/home/' .
          >> \ $USERNAME . '/.bashrc -i'
          >> " Depending on how vim is launched, c:/cygwin/home/$USERNAME
          >> " will sometimes be equivalent to ~. If so, then it will be
          >> " replaced by ~ in &shell.
          >
          > Wow... that looks complicated.

          I think it looks complicated at first glance, but it's only one vim
          command. The rest is either comments explaining the one command, or
          commented-out alternative commands along with why they were not used.
          I deliberately left them because if people started to customize the
          one command line, those are the obvious alternatives (at least they
          were to me) and I wanted to save them the lengthy troubleshooting to
          find out that it didn't work.

          > Why don't you just set
          > SHELL=C:/Bin/Bash.exe
          >
          > I have my cygwin in C:/
          >
          > In my system environment vars (controlpanel->system->
          > advanced system settings(system properties)->Advanced->
          > Environment variables->System Variables,
          > I have:
          >
          > DISPLAY=:0
          > CYGWIN=nodosfilewarning winsymlinks export
          > PATH=C:\prog64\vim;%SystemRoot%\system32;%SystemRoot%;C:\bin;[other
          > stuff]...
          > SHELL=C:/Bin/Bash.exe
          >
          > Bash starts and runs it's RC vars, which pick up my home.. and
          > that runs my .bashrc.
          >
          > One of the aliases I have in my bash startup files
          > for gvim is "setsid gvim"
          >
          > That allows gvim to run in the background...
          >
          > Would that work for you?
          >
          > I let bash & cygwin figure out my userid and home ..

          Interesting. I did not know that the shell could be set like that.
          But it makes sense.

          As for setsid, I'm shelling out from the Windows-based gvim, so I'm
          not sure if I really want bash to run in "separate session". It's not
          clear to me what that means, from the setsid man and info pages.
          However, if it's the same as appending an ampserand to a bash command
          so that it runs in the background, then I probably don't want that.
          Shelling out from vim is a trick for using a bash command as a filter
          for a lot of text, so the user would want vim to wait for the output
          to come back before proceeding.

          I don't know if setting the environment variable SHELL would propagate
          its value into the vim option "shell". However, even if it did, I
          would feel more comfortable with the command in my code because just
          setting the shell alone left the rc file un-executed, even with the
          interactive flag was provided as part of the "shell" option (which is
          suppose to cause the rc file to run). It's all kind of foggy to me
          now, but I believe that one of the possible causes was that $HOME was
          being set to different things depending on how vim was invoked. So it
          wasn't finding the rc file in many cases.

          Thanks for sharing though. I feel a bit more smarter after looking up
          stuff based on your examples.

          --
          You received this message from the "vim_use" 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
        • Alessandro Antonello
          ... I never tried to shelling using cygwin bash on Windows GVim. I will give a shot. In respect to ~ to be recognized as $HOME you will need to create an
          Message 4 of 9 , Sep 16, 2012
          • 0 Attachment
            >> AndyHancock wrote:
            >>> This problem dogged me for many years, and I finally hunkered down
            >>> to chase it down.
            >>>
            >>> Here is the solution that I found works for me:
            >>>
            >>> "set shell=c:\cygwin\bin\bash.exe\ -i
            >>> "Won't always find ~/.bashrc cuz depending on how vim is
            >>> "launched, ~ doesn't always resolve to c:/cygwin/home/$USERNAME

            > I don't know if setting the environment variable SHELL would propagate
            > its value into the vim option "shell". However, even if it did, I
            > would feel more comfortable with the command in my code because just
            > setting the shell alone left the rc file un-executed, even with the
            > interactive flag was provided as part of the "shell" option (which is
            > suppose to cause the rc file to run). It's all kind of foggy to me
            > now, but I believe that one of the possible causes was that $HOME was
            > being set to different things depending on how vim was invoked. So it
            > wasn't finding the rc file in many cases.

            I never tried to shelling using cygwin bash on Windows GVim. I will give a shot.
            In respect to '~' to be recognized as $HOME you will need to create an
            environment
            variable, in Windows, targeting that path. Be prepared that if you
            have any other
            cross platform software it probably will use that %HOME% path to write
            temporary
            and configuration specific files (Inkscape, GIMP, Dia, etc.).

            The best thing about this configuration is that both Windows Vim/Gvim and cygwin
            vim uses the same user runtime path (~/.vim) with save me for synchronizing
            plugins, syntaxes, colors, etc.

            --
            You received this message from the "vim_use" 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
          • AndyHancock
            On Sep 16, 1:22 pm, Alessandro Antonello ... The full code was: set shell=c: cygwin bin bash.exe -i Won t always find ~/.bashrc
            Message 5 of 9 , Sep 16, 2012
            • 0 Attachment
              On Sep 16, 1:22 pm, Alessandro Antonello <antonello....@...>
              wrote:
              >>>AndyHancock wrote:
              >>>> This problem dogged me for many years, and I finally hunkered
              >>>> down to chase it down.
              >>>>
              >>>> Here is the solution that I found works for me:
              >>>>
              >>>> "set shell=c:\cygwin\bin\bash.exe\ -i
              >>>> "Won't always find ~/.bashrc cuz depending on how vim is
              >>>> "launched, ~ doesn't always resolve to
              >>>> "c:/cygwin/home/$USERNAME

              The full code was:
              "set shell=c:\cygwin\bin\bash.exe\ -i
              "Won't always find ~/.bashrc cuz depending on how vim is launched,
              "~ doesn't always resolve to c:/cygwin/home/$USERNAME
              "let &shell='c:\cygwin\bin\bash.exe\ --rcfile c:\cygwin\home\' .
              " \ $USERNAME . '\.bashrc'
              "Backslashes are hated by bash. Also needs -i to ensure bash is
              "interactive so that .bashrc is sourced
              let &shell='c:\cygwin\bin\bash.exe --rcfile c:/cygwin/home/' .
              \ $USERNAME . '/.bashrc -i'
              " Depending on how vim is launched, c:/cygwin/home/$USERNAME
              " will sometimes be equivalent to ~. If so, then it will be
              " replaced by ~ in &shell.

              I said in my response to Linda that this only looks complicated
              because I also included the ones that didn't work (for me) to save
              experimenters the trouble of finding that out themselves. Hence there
              are comments explaining what didn't work, what did, and my best
              rationalization of why.

              >> I don't know if setting the environment variable SHELL would
              >> propagate its value into the vim option "shell". However, even if
              >> it did, I would feel more comfortable with the command in my code
              >> because just setting the shell alone left the rc file un-executed,
              >> even with the interactive flag was provided as part of the "shell"
              >> option (which is suppose to cause the rc file to run). It's all
              >> kind of foggy to me now, but I believe that one of the possible
              >> causes was that $HOME was being set to different things depending
              >> on how vim was invoked. So it wasn't finding the rc file in many
              >> cases.
              >
              > I never tried to shelling using cygwin bash on Windows GVim. I will
              > give a shot. In respect to '~' to be recognized as $HOME you will
              > need to create an environment variable, in Windows, targeting that
              > path. Be prepared that if you have any other cross platform software
              > it probably will use that %HOME% path to write temporary and
              > configuration specific files (Inkscape, GIMP, Dia, etc.).
              >
              > The best thing about this configuration is that both Windows
              > Vim/Gvim and cygwin vim uses the same user runtime path (~/.vim)
              > with save me for synchronizing plugins, syntaxes, colors, etc.

              I suspect that the lack of a defined Windows %HOME% variable (and
              hence, the automatic predefinition of unix $HOME) could very have been
              the cause of the problems I described above. I haven't experimented
              how robust is the solution of setting %HOME%. For example, what
              happens if you were logged into a non-administrator account and ran
              Windows gvim as MyAdminAccount, and administrator account.

              And in Windows 7, there is another way to invoke apps, "As
              Administrator", where Administrator isn't necessarily an account.
              Somehow, it knows that you are referring to MyAdminAccount, but
              running "As Administrator" further runs with elevated privileges,
              which simply running as MyAdminAccount does not. Environment
              variables also seem to differ. Not sure if either method of running
              as MyAdminAccount would pick up that account's %HOME% variable, since
              you don't actually log onto that account. (Not something I can test
              right now cuz I'm scanning a slow stick, which has taken more than a
              week).

              I'll wait until I get more info about the robustness of the solution
              of setting %HOME%, either from myself, you, or someone else.

              Thanks for the added knowledge, though, of how the problem could be
              circumvented.

              --
              You received this message from the "vim_use" 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
            • Alex Rodriguez
              ... Thanks Linda, this worked perfectly for me. Though I did leave the set shell=... in my vimrc. -- You received this message from the vim_use maillist.
              Message 6 of 9 , Jan 10, 2013
              • 0 Attachment
                On Friday, September 7, 2012 1:10:17 AM UTC-4, Linda W wrote:
                > AndyHancock wrote:
                >
                > > This problem dogged me for many years, and I finally hunkered down to
                >
                > > chase it down.
                >
                > >
                >
                > > Here is the solution that I found works for me:
                >
                > >
                >
                > > "set shell=c:\cygwin\bin\bash.exe\ -i
                >
                > > "Won't always find ~/.bashrc cuz depending on how vim is launched,
                >
                > > "~ doesn't always resolve to c:/cygwin/home/$USERNAME
                >
                > > "let &shell='c:\cygwin\bin\bash.exe\ --rcfile c:\cygwin\home\' .
                >
                > > " \ $USERNAME . '\.bashrc'
                >
                > > "Backslashes are hated by bash. Also needs -i to ensure bash is
                >
                > > "interactive so that .bashrc is sourced
                >
                > > let &shell='c:\cygwin\bin\bash.exe --rcfile c:/cygwin/home/' .
                >
                > > \ $USERNAME . '/.bashrc -i'
                >
                > > " Depending on how vim is launched, c:/cygwin/home/$USERNAME
                >
                > > " will sometimes be equivalent to ~. If so, then it will be
                >
                > > " replaced by ~ in &shell.
                >
                > >
                >
                > > Thanks to all those who helped on the unix, bash, cygwin, and vim
                >
                > > forums.
                >
                > >
                >
                > >
                >
                > Wow... that looks complicated.
                >
                >
                >
                > Why don't you just set
                >
                > SHELL=C:/Bin/Bash.exe
                >
                >
                >
                > I have my cygwin in C:/
                >
                >
                >
                > In my system environment vars (controlpanel->system->
                >
                > advanced system settings(system properties)->Advanced->
                >
                > Environment variables->System Variables,
                >
                > I have:
                >
                >
                >
                > DISPLAY=:0
                >
                > CYGWIN=nodosfilewarning winsymlinks export
                >
                > PATH=C:\prog64\vim;%SystemRoot%\system32;%SystemRoot%;C:\bin;[other
                >
                > stuff]...
                >
                > SHELL=C:/Bin/Bash.exe
                >
                >
                >
                > Bash starts and runs it's RC vars, which pick up my home.. and
                >
                > that runs my .bashrc.
                >
                >
                >
                > One of the aliases I have in my bash startup files
                >
                > for gvim is "setsid gvim"
                >
                >
                >
                > That allows gvim to run in the background...
                >
                >
                >
                > Would that work for you?
                >
                >
                >
                > I let bash & cygwin figure out my userid and home ..

                Thanks Linda, this worked perfectly for me. Though I did leave the "set shell=..." in my vimrc.

                --
                You received this message from the "vim_use" 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
              Your message has been successfully submitted and would be delivered to recipients shortly.