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

.bash_profile sourced when mvim is invoked

Expand Messages
  • J Irving
    Hi I just switched to bash, having been using zsh for a few years, and I notice that when I start MacVim using the mvim script, my ~/.bash_profile file is
    Message 1 of 3 , Jun 27, 2011
    • 0 Attachment
      Hi

      I just switched to bash, having been using zsh for a few years, and I notice that when I start MacVim using the mvim script, my ~/.bash_profile file is sourced. I'm pretty sure this file should only be sourced if bash is started interactively, which is not the case here. Anyone know why this is happening? And ideally how to prevent it?

      Thanks.

         cheers, J

      --
      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
    • Ben Schmidt
      ... Bash s startup behaviour is pretty braindead, IMHO. ~/.profile or ~/.bash_profile is sourced for a login shell. ~/.bashrc is sourced for an interactive
      Message 2 of 3 , Jun 27, 2011
      • 0 Attachment
        On 28/06/11 7:44 AM, J Irving wrote:
        > Hi
        >
        > I just switched to bash, having been using zsh for a few years, and I
        > notice that when I start MacVim using the mvim script, my
        > ~/.bash_profile file is sourced. I'm pretty sure this file should only
        > be sourced if bash is started interactively, which is not the case
        > here. Anyone know why this is happening? And ideally how to prevent
        > it?

        Bash's startup behaviour is pretty braindead, IMHO.

        ~/.profile or ~/.bash_profile is sourced for a login shell.

        ~/.bashrc is sourced for an interactive non-login shell.

        Except for ssh logins, ~/.bashrc is sourced even in the non-interactive
        case, and even though it's a login (so the exact opposite of what
        ~/.bashrc is usually for).

        A non-interactive non-login shell has nothing sourced (except for some
        script that can be named in an environment variable).

        MacVim starts a login shell when it spawns Vim processes, because that's
        what most users expect, and what Terminal.app does when you open a new
        window. The shell MacVim spawns is non-interactive, though, not
        interactive, of course. However, it results in ~/.profile or
        ~/.bash_profile being sourced.

        What a lot of people do is have ~/.profile or ~/.bash_profile do things
        they want in all login shells, and have that *also* source ~/.bashrc to
        do things they want only in interactive shells. Something like this:

        if echo $- | grep -q i ; then
        [ -r ~/.bashrc ] && source ~/.bashrc
        fi

        Getting ssh logins to do something sane is another nightmare. I have
        code for that if anyone is interested, as well as more extensive code to
        integrate the same kind of behaviour system-wide using /etc/profile and
        so on. Just let me know if you want a copy and I will gather it together
        and send.

        Hope this helps!

        Ben.



        --
        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
      • J Irving
        Hi Ben Thanks for your response and explanation of bash s startup behaviour. It is, I agree, braindead. However, I m determined to stick with this for a while,
        Message 3 of 3 , Jun 30, 2011
        • 0 Attachment
          Hi Ben

          Thanks for your response and explanation of bash's startup behaviour.
          It is, I agree, braindead. However, I'm determined to stick with this
          for a while, rather than running back to zsh as normally happens...

          On Jun 27, 9:41 pm, Ben Schmidt <mail_ben_schm...@...> wrote:
          > MacVim starts a login shell when it spawns Vim processes, because that's
          > what most users expect, and what Terminal.app does when you open a new
          > window. The shell MacVim spawns is non-interactive, though, not
          > interactive, of course. However, it results in ~/.profile or
          > ~/.bash_profile being sourced.
          >
          > What a lot of people do is have ~/.profile or ~/.bash_profile do things
          > they want in all login shells, and have that *also* source ~/.bashrc to
          > do things they want only in interactive shells. Something like this:
          >
          > if echo $- | grep -q i ; then
          >    [ -r ~/.bashrc ] && source ~/.bashrc
          > fi

          This works. Thanks for your help.

          > Getting ssh logins to do something sane is another nightmare. I have
          > code for that if anyone is interested, as well as more extensive code to
          > integrate the same kind of behaviour system-wide using /etc/profile and
          > so on. Just let me know if you want a copy and I will gather it together
          > and send.

          That would be useful, thanks. No hurry though, I don't have a problem
          this would solve (yet).

          > Hope this helps!

          Very much.

          cheers, J

          --
          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
        Your message has been successfully submitted and would be delivered to recipients shortly.