direnv and iterm2 shell integration
Thanks for filing an issue! Please answer the questions below so I can help you.
- iTerm2 version: 3.2.9
- OS version: macOS Mojave 10.14.5
- Attach com.googlecode.iterm2.plist here (drag-drop from finder into this window)
- Attach a debug log, if possible. Instructions at https://iterm2.com/debuglog
- Are you reporting a performance issue, excessive CPU usage, or a hang? Please attach a sample. Instructions at https://gitlab.com/gnachman/iterm2/wikis/HowToSample
- Are you reporting a crash? Please attach the crash log. Instructions at https://gitlab.com/gnachman/iterm2/wikis/crash-logs
- Are you reporting excessive memory usage? Please attach a heap analysis: https://gitlab.com/gnachman/iterm2/wikis/heapshot
Detailed steps to reproduce the problem:
- Install iterm2 shell integration (bash)
- Install direnv
- Add hooks to end of the appropriate file, in my case
~/.profile
This issue has also been raised by someone else previously with direnv devs and they have suggested raising this here, see https://github.com/direnv/direnv/issues/502
What happened:
direnv requires this line to be added to the end of your profile ( or bash_profile or bashrc etc depending on OS and your setup)
eval "$(direnv hook bash)"
This sources some direnv code and also changes the value of $PROMPT_COMMAND
$ type $PROMPT_COMMAND
_direnv_hook
The issue is that iterm shell integration clobbers the value of $PROMPT_COMMAND with __bp_precmd_invoke_cmd;__bp_interactive_mode
If I then manually $ source ~/.profile
then direnv works as expected for the duration of the bash session.
What should have happened:
It looks to me like the __bp_install_after_session_init()
function ln372 in the .iterm_shell_integration.bash
file makes some attempt to capture the previous $PROMPT_COMMAND
and stuff it into bash-preexec's precmd_functions
, which would then be run in theory by __bp_precmd_invoke_cmd
however that doesn't appear to be happening.
As a (possibly broken) workaround I've manually modified my copy of .iterm_shell_integration.bash
, changing ln356 to PROMPT_COMMAND="__bp_precmd_invoke_cmd; __bp_interactive_mode; _direnv_hook"
, i.e. I appended _direnv_hook
.
This does appear to work but I feel like this is a guess-hack at best.
Is there a way to provide/hook custom functions to the iterm2 shell integration so they run in precmd?
I also define a custom iterm2_generate_ps1
function in my profile which is working, which to me is shows there is precedent for hooking custom things into the shell integration.