Fix prompt issue for non-login subshells in OS X

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.
pull/709/head
Claudia 2016-04-21 19:05:49 +02:00
parent bc2ae26fa8
commit 3f05d6b3fd
1 changed files with 4 additions and 1 deletions

View File

@ -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