bash-git-prompt
bash-git-prompt copied to clipboard
iTerm2 shell integration breaks GIT_PROMPT_COMMAND_FAIL
I'm not sure if this is a bash-git-problem or an iTerm2 problem, but I noticed that afteri installing iterm2 shell integration, the git prompt always says ✔
17:09 $ false
✔ ~
17:09 $ echo $?
1
if I uninstall it, it works correctly
17:09 $ false
✘-1 ~
Could not reproduce currently. Where do you source the .iterm2_shell_integration.bash
? Before or after the git prompt? Also have you tried to update the iterm2_shell_integration.bash
?
tried sourcing before and after git prompt , same result. I updated it right before doing the test.
Is there anything else I can do to troubleshoot?
I have the same issue
Same here. Also seeing an error about needing an integer.
✔ whoami@hostname ~/<folder> [<gitBranch>|…7]
14:30 $ hey
-bash: hey: command not found
-bash: test: <gitBranch>: integer expression expected
which Git version do you have?
I use Xcode 9.0.1 on OS X High Sierra. In Xcode the git is included. git version 2.13.5 (Apple Git-94)
But it happens also with other git versions.
On 22 Oct 2017, at 15:50, Martin Gondermann [email protected] wrote:
which Git version do you have?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/magicmonty/bash-git-prompt/issues/348#issuecomment-338479034, or mute the thread https://github.com/notifications/unsubscribe-auth/AE9lbRtqiwGBf6AYuQFgsfpUf736P6dVks5su0g1gaJpZM4PfeOc.
Same thing. Tried to source gitprompt.sh
in ~/.profile
before and after iTerm's bash integration.
- git version 2.15.0
- iTerm2 Build 3.1.5
- macOS Sierra 10.12.6
So, after some digging into this, this is, IMO, a problem with the iterm2 integration.
What happens is that, when when initially installed, PROMPT_COMMAND
is set to
PROMPT_COMMAND=setLastCommandState; trap '__bp_preexec_invoke_exec "$_"' DEBUG; __bp_install;setGitPrompt
So far, so good. GitPrompt still gets the error state of the last command early on, and doesn't reset it, so everyone else can also get it if they want it. However, as soon as the first prompt is rendered, then __bp_install is called, which sets the PROMPT_COMMAND
to:
PROMPT_COMMAND=__bp_precmd_invoke_cmd; setLastCommandState; setGitPrompt; __bp_interactive_mode
Here __bp_precmd_invoke_cmd does not preserve the state of $?, and so by the time it gets to setLastCommandState
it is already set to 0
, and so GitPrompt cannot get the correct value. As an aside, this two phase setup also explains why it doesn't matter which order the two prompts are installed, since __bp_install
is always called last, and it gets to determine the processing order.
There are (at least?) three possible solutions:
- if
__bp_last_ret_value
is set, use it instead of$?
, or - Use the bash preexec hooks as well, or
- Get bash preexec (and by extension iterm2) to fix the initial hook to preserve
$?
A workaround for users is to define the following function after importing GitPrompt:
# Temporary workaround for the interations defined in
# https://github.com/magicmonty/bash-git-prompt/issues/348
function setLastCommandState() {
GIT_PROMPT_LAST_COMMAND_STATE=$__bp_last_ret_value
}
Once this new function is installed then everything works as expected, but it would be nice if this could be done automatically in some fashion.
@pwagland - Thanks for including all that information; I'm seeing this too. I tried to enter your workaround code snippet in my ~/.bash_profile
, both after the entire block recommended for installation:
if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
__GIT_PROMPT_DIR=$(brew --prefix)/opt/bash-git-prompt/share
source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
fi
# Temporary workaround for the interations defined in
# https://github.com/magicmonty/bash-git-prompt/issues/348
function setLastCommandState() {
GIT_PROMPT_LAST_COMMAND_STATE=$__bp_last_ret_value
}
and within it:
if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
__GIT_PROMPT_DIR=$(brew --prefix)/opt/bash-git-prompt/share
source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
# Temporary workaround for the interations defined in
# https://github.com/magicmonty/bash-git-prompt/issues/348
function setLastCommandState() {
GIT_PROMPT_LAST_COMMAND_STATE=$__bp_last_ret_value
}
fi
Further attempts to do stuff in the terminal resulted in error statues of -
with the following output:
✘- ~/workspace [master|●4✚ 1…1]
15:56 $ . ~/.bash_profile
-bash: [: =: unary operator expected
-bash: [: =: unary operator expected
-bash: [: =: unary operator expected
iTerm2 build is Build 3.1.5
.
This persisted even when I sourced a bash profile that only had the above code as its content, so I don't think that any other stuff from the profile interfered, but maybe I am missing something.
Did I put the code snippet in the correct place?
@jwfriese Oei. I have no idea. My guess is that you have a different issue, although probably related. My best guess is that $__bp_last_ret_value
is not set, and so GIT_PROMPT_LAST_COMMAND_STATE
ends up being an empty string, and therefore you get the errors when checking it. I suggest to look at you PROMPT_COMMAND
, and if it doesn't start with __bp_precmd_invoke_cmd;
then you need to look at whatever is there, and what it is doing to steal your $? value.
This is still an issue. I can reproduce all the issues in this ticket including the proposed workaround failing the same way as @jwfriese mentioned.
In addition I am running the latest of all tooling
Unfortunately I don't have a Mac anymore. Maye someone can issue a PR?