2

From my testing, it's clear that nvim doesn't source your .bash_profile when opening a new terminal buffer. I would like to force this to happen every time a new terminal buffer is created.

To confirm this behavior:

  1. open your .bash_profile in nvim
  2. export a new variable like ISSOURCED
  3. write out the file
  4. open a terminal buffer
  5. run echo $ISSOURCED

I've also checked that bash is running in interactive mode (it is) by executing if tty -s; then echo interactive; fi, based on this answer

However it is not a login shell, based on executing shopt -q login_shell && echo 'Login shell' || echo 'Not login shell', based on this answer. This means that it would normally source $HOME/.bashrc. Unfortunately I keep my bashrc in a different location and source it from my .bash_profile, so it isn't being picked up.

See my answer below for my current workaround and information about why it's less than ideal.

Floegipoky
  • 3,087
  • 1
  • 31
  • 47
  • 2
    Does nvim source your bashrc file instead? – bstamour Nov 25 '15 at 21:10
  • 2
    `.bash_profile` is only sourced by login shells, while `nvim` is likely starting a regular interactive shell instead. – chepner Nov 25 '15 at 21:29
  • @bstamour You should post an answer involving adding 'source $HOME/.bash_profile` to $HOME/.bashrc, I'll upvote it since you deserve the rep for pointing me in that direction and it will be useful advice for future readers. However that still won't work for me because I don't have a $HOME/.bashrc, so I won't mark it as accepted. – Floegipoky Nov 25 '15 at 21:42

2 Answers2

1

Add this to your ~/.vimrc:

set shell=bash\ -l

When invoked with -l (--login), bash reads your ~/.profile at startup (among other files) and thus everything sourced from there.

When invoked with -i (--interactive), bash reads your ~/.bashrc at startup (among other files) and thus everything sourced from there.

$ man bash or :h shell and :h shellcmdflag for more info.

Taken from: https://stackoverflow.com/a/9092644/1071756

João Pesce
  • 2,424
  • 1
  • 24
  • 26
0

I set up a mapping to open a new terminal:

nnoremap <leader>z :new<CR>:terminal<CR>

To source my .bash_profile, I changed it to this:

nnoremap <leader>z :new<CR>:terminal<CR>source $HOME/.bash_profile<CR>c<CR>

The problem with this solution is that it breaks if you try to open a terminal buffer in any way other than with this mapping

Floegipoky
  • 3,087
  • 1
  • 31
  • 47