5

Possible Duplicate:
Change cursor shape (or color) to indicate vi mode in bash

I am using vi-mode in a bash shell, and I would like to change the PS1 variable whenever I am in insert mode. When I run bind -v | awk '/keymap/ {print $3}', the result is vi-insert for insert mode and vi for normal mode.

I would like some visual indicator of which mode I am in, such as a yellow prompt or a dot, something like this:

enter image description here

I would like this visual change to happen as soon as the mode changes, even if no command is run. Is it possible to change the value of PS1 for the current process and update the prompt without hitting enter?

tlehman
  • 581
  • Don't think this is possible - bash only prints the prompt when you do things like hit enter or clear the screen. And readline key-binding only supports binding a key to a single action - otherwise I'd suggest binding your mode-switch key to also update the prompt. – jw013 Oct 31 '12 at 17:59
  • 1
    This questions was asked over at stackoverflow. – donothingsuccessfully Oct 31 '12 at 18:06
  • 1
    Ah, unfortunately it doesn't look like either of those questions have affirmative answers either. Changing cursor is not quite the same as changing the prompt, so I'd vote as not a duplicate, and there's no way to flag cross-site duplicates, unfortunately. – jw013 Oct 31 '12 at 18:11
  • @jw013 If I bind Escape or my shortcut "kj" to change PS1, will the prompt update before I hit enter? – tlehman Oct 31 '12 at 18:31
  • @TobiLehman No, PS1 is only used to print the prompt - changes to it will only visible the next time it is used. You would need the mapping to cause the prompt to be rewritten or to rewrite it yourself. – jw013 Oct 31 '12 at 18:36
  • @jw013 Is there a filesystem hook for re-writing the prompt? – tlehman Oct 31 '12 at 18:38
  • @TobiLehman Not sure what you mean by "filesystem hook". – jw013 Oct 31 '12 at 18:44
  • 1
    If switching to zsh is an option, see this question – Stéphane Chazelas Oct 31 '12 at 19:59
  • @StephaneChazelas I think this is going to be the thing that sells me on zsh. – tlehman Oct 31 '12 at 20:06

0 Answers0