created: 2024-11-01T06:32:34.846Z

[bash] PROMPT_COMMAND の設定で direnv が効かなくなる場合の対処

direnv も、bash-preexec も、両方 PROMPT_COMMAND 変数に依存したツールである。

いちばん簡単な解決法としては、.bashrc で direnv hook bash の実行を最後にすればよい。

export PROMPT_COMMAND="prompt_cmd"
which direnv >/dev/null && eval "$(direnv hook bash)"

direnv は既存の PROMPT_COMMAND を壊さないように処理をいれこんでくれる。

参考

The most common solution is to make sure that eval "$(direnv hook bash)" is the last command executed during the bash startup. Because direnv is playing nicely and making sure that it will be executed first.

縁の下のUIデザイン──小さな工夫で大きな効果をもたらす実践TIPS&テクニック (WEB+DB PRESS plus)
[ad] 縁の下のUIデザイン──小さな工夫で大きな効果をもたらす実践TIPS&テクニック (WEB+DB PRESS plus)
池田 拓司 (単行本(ソフトカバー))