I wanted to write some scripts and have MacVim call some bash commands. I have some aliases and wanted vim to be able to call them, so I knew I needed a login shell, just didn't know how to make vim use one.
I read this: https://stackoverflow.com/questions/4642822/vim-is-not-obeying-command-aliases (which didn't work for my MacVim); and this: https://stackoverflow.com/questions/4642822/vim-is-not-obeying-command-aliases which seemed like a good idea.
So I opened my .vimrc and put this in: set shell=/bin/bash\ -l
.
Now something very strange is happening: I have an alias in my .bash_profile
, like so:
alias mytest='echo "TEST!!"'
My .bashrc
sources .bash_profile
, so I know it shouldn't be a matter of where the alias is set. If I go inside vim and run: :! alias mytest
I see this:
alias mytest='echo "TEST!!"'
Press ENTER or type command to continue
If I run :! mytest
, though, this is what I get:
/bin/bash: mytest: command not found
shell returned 127
Press ENTER or type command to continue
So I'm all out of ideas about how this can be happening. How come when I run "alias" the alias is there, but when I run the alias itself, bash doesn't recognize it?
I appreciate any insight anyone can give me on this matter.
Thank you.
UPDATE:
I now tried changing my .vimrc
line to:
set shell=/bin/bash\ -li
In order to make the shell interactive as well as being a login shell, and it worked.
So I change my question a bit: Why does this make sense? As I understand it, a login shell runs my .bash_profile
, and thus loads my aliases. Why is it not sufficient?