Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

powerline and iTerm2 shell integration no longer working together #1844

Closed
lastobelus opened this issue Oct 9, 2017 · 7 comments
Closed

Comments

@lastobelus
Copy link

iTerm2: Build 3.1.4.beta.1
powerline: 2.6

Contents of bash_login:

# iterm shell integration
test -e ${HOME}/.iterm2_shell_integration.bash && source ${HOME}/.iterm2_shell_integration.bash

# powerline prompt
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /usr/local/lib/python2.7/site-packages/powerline/bindings/bash/powerline.sh

Contents of $PROMPT_COMMAND:

__bp_precmd_invoke_cmd; _powerline_set_prompt; __bp_interactive_mode

The very first prompt of a shell works (iterm's little chevron is present and the first command gets recorded in Toolbelt > Command History

All subsequent prompts do not call the iterm shell integration functions.

The behaviour is the same regardless of who is given first crack at PS1 (ie, if I move the iterm shell integration initializer below powerline's).

@ZyX-I
Copy link
Contributor

ZyX-I commented Oct 9, 2017

You must have something else in the bashrc, neither iTerm shell integration nor powerline defines __bp_precmd_invoke_cmd. First deal with that, I do not see any issues with iTerm integration except for that it has a bug.

Also when I have

POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
source ~/.vam/powerline/powerline/bindings/bash/powerline.sh

source ~/tmp/iterm2_shell_integration

PROMPT_COMMAND is _powerline_status_wrapper _powerline_set_prompt; iterm2_preexec_invoke_cmd as expected (though I can’t verify it is working as expected without iTerm2). (Status wrapper is a recent addition, not in release yet.)

I must say though that iTerm2 shell integration contains a serious bug which prevents powerline prompt from working correctly in case somebody (including powerline itself which it does when run in tmux unless tmux integration is disabled, though iterm integration does not support tmux so it did not hit them yet) is using the same method of appending to PROMPT_COMMAND: it has

        PROMPT_COMMAND="$(echo -n $PROMPT_COMMAND | sed -e 's/; *$//'); iterm2_preexec_invoke_cmd";

: note that $PROMPT_COMMAND is not quoted. Somebody needs to tell to the issue tracker that

  1. It must be quoted to preserve newlines, double spaces in literals, etc.

  2. The whole sed thing with the whole if is completely useless, just they should not use semicolon and instead write

    PROMPT_COMMAND="$PROMPT_COMMAND"$'\niterm2_preexec_invoke_cmd'

    : the bug they are referring to is not going to appear if one uses newline as a command separator because one can have any amount of newlines as separators they need and leave trailing or leading newlines without any issues (so without bothering to check whether $PROMPT_COMMAND is empty in the first place: this line is to replace all six if lines they have in iterm2_preexec_install).

In any case I do not see this as powerline or iterm integration issue, deal with whatever is adding _bp… thingies.

@lastobelus
Copy link
Author

iTerm2 definitely uses bash-preexec -- it's where bash-preexec originated. I think you're looking at an old version of the iterm2 shell integration, from before bash-preexec was extracted.

(And, FYI the weird sed is gone -- but wasn't it there because of how powerline used to set up the PROMPT_COMMAND?)

@lastobelus
Copy link
Author

In any case, the latest release (v0.3.4) of bash-preexec fixes the issue. The new version uses a DEBUG trap to add any new things added to PROMPT_COMMAND to the set of bp preexec commands, which has the side effect of powerline no longer showing up in the PROMPT_COMMAND var:

echo $PROMPT_COMMAND
__bp_precmd_invoke_cmd; __bp_interactive_mode

@lastobelus
Copy link
Author

For anyone else googling up this issue until iterm2 incorporates the new bash-preexec: just copy-paste v0.3.4 into your iterm2_shell_integration.bash

@ZyX-I
Copy link
Contributor

ZyX-I commented Oct 11, 2017

@lastobelus I downloaded iTerm2 shell integration using the link suggested in https://www.iterm2.com/documentation-shell-integration.html (i.e. https://iterm2.com/misc/bash_startup.in) and it neither contains source or dot commands nor it defines __bp* functions, though it does create precmd/preexec hooks and it does contain sed.

@ricalo
Copy link

ricalo commented Dec 14, 2017

I had this same problem, my $PROMPT_COMMAND is:

echo $PROMPT_COMMAND
__bp_precmd_invoke_cmd; __bp_interactive_mode

The workaround for me was to append _powerline_set_prompt to the precmd_functions after sourcing powerline.sh in my bashrc:

...
# Regular powerline configuration
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
source <powerline_folder>/powerline.sh

# Next line is the workaround
precmd_functions+=(_powerline_set_prompt)
...

Hope this helps somebody.

@gino-m
Copy link

gino-m commented May 31, 2020

For others coming across the same issue 2 1/2 years later, here's the workaround that worked for me with a recent release on Mac OS Mojave w/iTerm 2 installed:

function _powerline_set_prompt() {
    PS1="$(powerline-shell "$?")"
}

precmd_functions+=(_powerline_set_prompt)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants