I have the following in my .bashrc:
bind '"\e[A"':history-search-backward
bind '"\e[B"':history-search-forward
However, when I call shell from within Emacs, I get the following message:
bash: bind: warning: line editing not enabled
bash: bind: warning: line editing not enabled
And as a consequence my prompt gets messed up.
How can I detect (from within my .bashrc), that my shell is being called from emacs or, alternatively, not from a standard terminal?
My goal is to wrap the calls to bind so that they are only executed in a proper terminal.
Probing for a variable called EMACS didn't work for me under Emacs 25 and bash 4.2.
However, looking for differences in the environment of the shell within and outside of Emacs I found a variable called INSIDE_EMACS only set when running from Emacs.
The solution that worked for me is therefore:
if [[ ! -v INSIDE_EMACS ]]; then
bind '"\e[A"':history-search-backward
bind '"\e[B"':history-search-forward
fi
Echoing INSIDE_EMACS returns the Emacs release number.
bash disables line editing because when it sees a variable named EMACS in its environment. You can use the same variable to conditionally create those bindings:
if [[ ! -v EMACS ]]; then
bind '"\e[A"':history-search-backward
bind '"\e[B"':history-search-forward
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With