Closed janpieper closed 3 years ago
@janpieper I had a similar problem and tried adding asdf before direnv in my .bash_profile and that seems to have worked. YMMV
I got the same issue when using the powerline. i to put the asdf config before the powerline config in the .bashrc (as @olbrich mentioned) and worked.
My PROMPT_COMMAND
variable:
_direnv_hook;(_z --add "$(command pwd -P 2>/dev/null)" 2>/dev/null &); asdf_java_prompt_command;
How direnv deals with PROMPT_COMMAND variable:
_direnv_hook() {
local previous_exit_status=$?;
trap -- '' SIGINT;
eval "$("/usr/bin/direnv" export bash)";
trap - SIGINT;
return $previous_exit_status;
};
if ! [[ "${PROMPT_COMMAND:-}" =~ _direnv_hook ]]; then
PROMPT_COMMAND="_direnv_hook${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
fi
direnv will add _direnv_hook;
before the old content in PROMPT_COMMAND
variable.
How command z deals with PROMPT_COMMAND variable:
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# populate directory list. avoid clobbering other PROMPT_COMMANDs.
grep "_z --add" <<< "$PROMPT_COMMAND" >/dev/null || {
PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''(_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null &);'
}
}
command z will add (_z --add "$(command pwd -P 2>/dev/null)" 2>/dev/null &);
after the old content in PROMPT_COMMAND variable with ;
suffix.
How can I fix this question?
First, remove export
in set-java-home.bash.
change your .bashrc
, let asdf java bash script source
first, before direnv
and command z(and any other commands will change PROMPT_COMMAND variable).
or:
let command z source
first, and then use the patch in this commit, and then source
the asdf java home bash script.
Maybe we can change set-java-home.bash to:
if ! [[ "${PROMPT_COMMAND:-}" =~ prompt_command ]]; then
PROMPT_COMMAND="prompt_command${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
fi
BTW, we should use _asdf_java_prompt_command
instead of prompt_command
, which would be more specific to name a function from asdf-java plugin.
When using direnv and
set-java-home.bash
, thePROMPT_COMMAND
will be set to:This causes bash to cry, because it does not like
;;
:cry:I thought of checking whether
PROMPT_COMMAND
already ends with;
to avoid adding another;
, but I am not a bash expert. Maybe there is a better way to solve this issue.I am currently using this as a workaround:
PROMPT_COMMAND
will be set to_direnv_hook; :; prompt_command
. See this comment at Stackoverflow to understand what:
stands for.