oh-my-fish / theme-agnoster

MIT License
95 stars 64 forks source link

[WIP] Add right prompt with vi mode indicator #12

Closed olbrew closed 8 years ago

olbrew commented 8 years ago

I want to make a right prompt which shows a vim mode indicator. As you can see this is not yet fully functional, because there are some problems with the colour left. Can somebody point me in the right direction?

It would also probably be a good idea to only show this prompt if the user has vi mode enabled. I'll look around for how to do that.

sn0cr commented 8 years ago

Nice work! :+1:

To fix the color issue you need some of the lines from prompt_finish I just copied the lines from this function - I think that should be sufficient to fix the color problems that I saw.

    if [ -n $current_bg ]
      set_color -b normal
      set_color $current_bg
    end
    set -g current_bg NONE

bildschirmfoto 2015-12-07 um 00 04 35

olbrew commented 8 years ago

Thank you! This fixed some but not all my issues. The left arrow from the fish_right_prompt still has the same colour as the last (most right) colour from the fish_prompt.

I also couldn't find an easy way to only enable this prompt on fish_vi_mode as it is not an option that is set. The only way I can currently think of is manually parsing the config.fish for fish_vi_mode, but this seems unnecessary and unreliable as users can also manually enter fish_vi_mode. What do you think?

Thank you.

sn0cr commented 8 years ago

Concerning the colour of the first left arrow: I think the colour of the next line interferes with the colour of the current arrow. To fix this simply add a set_color colour before the line echoing the segment separatorn

Indeed parsing the config_fish is not reliable enough for the shell (or needs just too much time) Did you see the fish_vi_mode_source? According to this source __fish_vi_mode should be set to 1 if the vi mode is enabled.

Keep the nice work going. :smile:

olbrew commented 8 years ago

Concerning the colour of the first left arrow: I think the colour of the next line interferes with the colour >of the current arrow. To fix this simply add a set_color colour before the line echoing the segment separatorn

Awesome, this fixed the arrow issue.

Indeed parsing the config_fish is not reliable enough for the shell (or needs just too much time) Did you see the fish_vi_mode_source? According to this source __fish_vi_mode should be set to 1 if the vi mode is enabled.

I can indeed check this option and only then set this prompt. Problem is if you set fish_vi_mode in your config you already get an ugly indicator as defined here (This piece of code could've spared me a lot of time incidentally :smile: ). So what I do is I just manually set

set -g fish_key_bindings fish_vi_key_bindings

as defined here. This way I avoid the ugly indicator and only have mine.

I'll probably add the check in the repository so it doesn't break when someone doesn't use vi_mode and add a disclaimer in the README with the manual workaround.

When I've pushed that and you're happy with it you can merge if you want :). Thank you for your assistance!

olbrew commented 8 years ago

Ready to merge if you are :wink: .

sn0cr commented 8 years ago

You're welcome!

Ok thank you for your explanations, got me a good insight in the problems you've had. :smile: Would you mind refactoring you're code and add a right_prompt_segment like I did in this gist - (just copy and paste :wink:)? Then we have a (possibly) future proof code and we can finally merge!

Have a good evening - wherever you are. :wink:

olbrew commented 8 years ago

Sure, done. You a good evening as well.

On 08 Dec 2015, at 20:58, sn0cr notifications@github.com wrote:

You're welcome!

Ok thank you for your explanations, got me a good insight in the problems you've had.
Would you mind refactoring you're code and add a right_prompt_segment like I did in this gist - (just copy and paste ) https://gist.github.com/sn0cr/5476fdf38bd29f00ce33? Then we have a (possibly) future proof code and we can finally merge!

Have a good evening - wherever you are.

— Reply to this email directly or view it on GitHub https://github.com/oh-my-fish/theme-agnoster/pull/12#issuecomment-162997200.