1

I'm on MacOS, so basically all terminals are login terminals for me which source my bash_profile and load everything I need.

However, the :term command does not source my bash_profile, I believe because its not a login terminal.

I know I can use set shell=bash\ -l to do this, but that also causes Vim to source my bash_profile on load, which is slow.

Is there a way to only do this when actually running the term command in Vim?

Update Solved!

Ralf's idea worked perfectly. I also integrated in d-ben-knoble's interactive check as well.

if [[ -n "$PS1" && -f "$HOME/.bashrc" ]]; then
    source "$HOME/.bashrc"
fi

2

I would solve this in bash:

1) Move all setting that you need in login shells and non-login shells to the file .bashrc

2) Add the following to the end of your .bash_profile:

# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
fi

You could drop the if..., as the file always exists.

Background: The file .bashrc is source by bash if it is started as an interactive shell that is not a login shell. See man bash section "INVOCATION".


You .bash_profile will be rather empty, but that is ok. On Linux I use the file .profile (sourced by bash if .bash_profile is not available) and it only contains a few export statements and the source command for .bashrc.

  • I would additionally include a test for the interactive flag – D. Ben Knoble Apr 16 at 13:48
  • This works perfectly. I combined the original answer plus an interactive check as well, good idea! – convergedtarkus Apr 16 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.