Shell integration replace my powerline-shell prompt

342 views
Skip to first unread message

Jose Herran

unread,
Sep 24, 2014, 2:08:07 AM9/24/14
to iterm2-...@googlegroups.com
Is there a chance for both to work together?

Thanks

P Antes de imprimir este mensaje, asegúrate de que es necesario. Proteger el  medio ambiente está también en tu mano.

George Nachman

unread,
Oct 4, 2014, 3:40:53 PM10/4/14
to iterm2-...@googlegroups.com
(The following assumes you use bash)

There is. Unfortunately both Powerline and iTerm2 want to stomp on your PS1 from within PROMPT_COMMAND. When you install Powerline, you put something like this in your .bashrc:

function _update_ps1() {
   export PS1="$(~/powerline-shell.py $? 2> /dev/null)"
}
export PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"

There are three problems here:

1. iTerm2 will put its initialization in either .bash_profile or .profile. For sanity's sake, make sure both your Powerline and iTerm2 initialization are in the same file.

2. Changing PS1 at runtime isn't supported by shell integration. Instead, you need to change $orig_ps1, like so:

export orig_ps1="$(~/powerline-shell.py $? 2> /dev/null)"

3. If your $PROMPT_COMMAND was empty originally then Powerline kind of makes a mess by leaving a trailing ;. Get rid of that since you probably didn't have a preexisting $PROMPT_COMMAND. The final script you want is this:

function _update_ps1() {
   export orig_ps1="$(~/powerline-shell.py $? 2> /dev/null)"
}
export PROMPT_COMMAND="_update_ps1"

Make sure you have the latest shell integration code by reinstalling it (the very first version would stop on your existing $PROMPT_COMMAND, the latest does not).

--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Serodio

unread,
May 20, 2015, 5:27:24 PM5/20/15
to iterm2-...@googlegroups.com, gnac...@llamas.org
I use zsh, how would I go about mixing Powerline and iTerm2's shell integration?

I have the following on my .zshrc:

function powerline_precmd() {
  export PS1="$(~/.powerline-shell.py $? --cwd-max-depth 20 --shell zsh 2> /dev/null)"
}

function install_powerline_precmd() {
  for s in "${precmd_functions[@]}"; do
    if [ "$s" = "powerline_precmd" ]; then
      return
    fi
  done
  precmd_functions+=(powerline_precmd)
}

install_powerline_precmd

Thanks,
Daniel Serodio

George Nachman

unread,
May 21, 2015, 2:03:22 PM5/21/15
to iterm2-...@googlegroups.com
The zsh shell integration script didn't handle PS1 changing. I've fixed it. Please reinstall shell integration and let me know if you have any issues.

Daniel Serodio

unread,
May 25, 2015, 9:48:47 AM5/25/15
to iterm2-...@googlegroups.com
zsh + powerline-shell + iTerm2 working perfectly, thanks!

However, I use bash + liquidprompt[1] for remote shells, and I still haven't managed to make iTerm2 shell integration with those.

Regards,
Daniel Serodio

[1] https://github.com/nojhan/liquidprompt

George Nachman

unread,
May 27, 2015, 4:50:09 PM5/27/15
to iterm2-...@googlegroups.com
Unfortunately liquidprompt uses the DEBUG trap, and it steps on shell integration's trap. I can't fix the shell integration bash script to add its trap on top of liquidprompt's because DEBUG traps don't get passed through the "source" command. Here's a little hack that will let them coexist:

trap -- '_lp_reset_runtime;preexec_invoke_exec' DEBUG

Just put that in your .profile or .bash_profile.

Blair MacIntyre

unread,
Jun 2, 2016, 11:32:51 AM6/2/16
to iterm2-discuss
I see this topic is a bit old, but I just downloading iTerm2 v3 (when iTerm prompted me to) and I'd heard of iTerm's shell integration (which is pretty cool) ... but, since I use zsh, I assume the bash integration won't work out of the box ... searching here found this topic, and this is the first I've heard (also) of power line.  Now I want both!  :)

To get to the point:  assuming I have iTerm3 and use zsh, can anyone give me any tips on getting the shell integration and powerline working from scratch?  I am not a novice shell user, but I don't have prior experience with the pre-commands, DEBUG traps, etc.

Thanks for any pointers!

George Nachman

unread,
Jun 2, 2016, 7:34:59 PM6/2/16
to iterm2-...@googlegroups.com
Shell Integration works with zsh (I wrote separate scripts for different shells). I just tested it and it works fine with the powerline zsh extension.

Blair MacIntyre

unread,
Jun 3, 2016, 9:48:36 AM6/3/16
to iterm2-discuss, gnac...@llamas.org
Ok, cool, thanks.  I didn't notice that powerline-shell had different integrations already.  I was looking at what iterm2 installed (bash stuff), and thought I had to start there.

Installed, and working.  It's AWESOME.  Especially like the version control integration.  No more working in the wrong branch for me! :)

Thanks a ton.
Reply all
Reply to author
Forward
0 new messages