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.
Avoiding the if statements, using exit code of `grep -q` instead.
Reverted the change that adds a space after the AC char. Opting for a
default value, allowing to override from one's profile.
bash-it takes rather a while to startup, around 0.5 seconds on my
laptop. After a bit of timing it appears the majority of the time is
spent in themes/colors.theme.bash. The reason for that is the fancy
abstraction layers that use $(). For example, consider this code:
red="$(color reset red)"
It will go through 9 forkexecs to evaluate:
red="$(color reset red)"
"$(__color_parse make_ansi reset red)"
"$(__make_ansi reset red)"
"\[\e[$(__reset red)m\]"
"\[\e[0;$(__red)m\]"
"\[\e[0;$(__color red)m\]"
"\[\e[0;$(__color_normal_fg $(__color_red))m\]"
"\[\e[0;$(__color_normal_fg 1)m\]"
"\[\e[0;31m\]"
With all the variables in colors.theme.bash, this adds up to hundreds of
forks:
$ strace -f bash ./colors.theme.bash 2>&1 | grep clone | wc -l
649
The solution is to replace the function with its result:
-red="$(color reset red)"
+red='\[\e[0;31m\]'
This is safe, since colors.theme.bash never calls external functions or
takes any input. So, its result can be safely hard-coded.
This improves startup time dramatically. Try adding "time" to your .bashrc:
# Load Bash It
time source $BASH_IT/bash_it.sh
before:
real 0m0.462s
user 0m0.100s
sys 0m0.399s
after:
real 0m0.150s
user 0m0.091s
sys 0m0.064s
This change allows for the capture of the expanded prompt (rather than the raw `PS1`) so that
it is easier to maintain context when changing directories.
Fix is based on the comments from [this stackoverflow](http://stackoverflow.com/a/24006864)
See https://github.com/wting/autojump for more details.
Currently only supports the version installed through Homebrew on OS X.
Please feel free to provide a PR for supporting additional installation
options.