From 3f05d6b3fdeb0aaf227afd38dd622fc68aa99219 Mon Sep 17 00:00:00 2001 From: Claudia Date: Thu, 21 Apr 2016 19:05:49 +0200 Subject: [PATCH] Fix prompt issue for non-login subshells in OS X MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes an issue with themes on OS X which are sometimes left in a partially broken environment with missing dependencies. When a `BASH_IT_THEME` is active on OS X and has a dynamic `PROMPT_COMMAND` which is not exported, and such `PROMPT_COMMAND` is backed by shell functions which are not exported either, and at the same time the theme is not OS-X-aware (regarding `update_terminal_cwd`), and the user launches a (non-login) interactive subshell from the OS X Terminal, a `command not found` appears on every command invocation. The issue is caused by a regression in PR #514, which attempts to inject `update_terminal_cwd` into the prompt. As a side effect, it also escalates the exportedness of `PROMPT_COMMAND` while the theme-specific backing functions (which power the dynamic prompt) remain unexported. The subshell cannot recover from this partially broken environment because unlike in Linux, Bash-it on OS X is not invoked for non-login subshells. The dependencies remain broken which leads to the error. The fix is to preserve `PROMPT_COMMAND`’s exportedness on OS X, leaving the individual theme responsible for consistently exporting either all or nothing of its environment. --- plugins/available/osx.plugin.bash | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/available/osx.plugin.bash b/plugins/available/osx.plugin.bash index c1d2b18b..8a638b14 100644 --- a/plugins/available/osx.plugin.bash +++ b/plugins/available/osx.plugin.bash @@ -5,7 +5,10 @@ about-plugin 'osx-specific functions' if [ $(uname) = "Darwin" ]; then if type update_terminal_cwd > /dev/null 2>&1 ; then if ! [[ $PROMPT_COMMAND =~ (^|;)update_terminal_cwd($|;) ]] ; then - export PROMPT_COMMAND="$PROMPT_COMMAND;update_terminal_cwd" + PROMPT_COMMAND="$PROMPT_COMMAND;update_terminal_cwd" + declared="$(declare -p PROMPT_COMMAND)" + [[ "$declared" =~ \ -[aAilrtu]*x[aAilrtu]*\ ]] 2>/dev/null + [[ $? -eq 0 ]] && export PROMPT_COMMAND fi fi fi