justjanne / powerline-go

A beautiful and useful low-latency prompt for your shell, written in go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vim mode indicator is not a powerline segment

xsteadfastx opened this issue · comments

Describe the bug
i love to use the vi mode in fish. but the indicator is not shown as a powerline segment. its shown completly to the left side.

Environment (please complete the following information):

  • OS: linux
  • Architecture: x86_64
  • Shell: fish

grafik

Same issue on

  • macOS + fish (amd64)
  • Arch + fish (amd64, armv7)
  • Raspbian + fish (armv6)
  • Ubuntu + fish (armv7)

Actually that's more a missing feature, here's my workaround on zsh:

#!/usr/bin/env zsh

set opt prompt_subst
export VI_MODE_RESET_PROMPT_ON_MODE_CHANGE=true
export MODE_INDICATOR="%F{yellow}+%f"

export BASE_PROMPT=$PROMPT

setopt promptsubst
zmodload zsh/datetime
autoload -U add-zsh-hook

function preexec() {
  __TIMER=$EPOCHREALTIME
}

function powerline_precmd() {
  local __ERRCODE=$?
  local __DURATION=0

  if [ -n $__TIMER ]; then
    local __ERT=$EPOCHREALTIME
    __DURATION="$(($__ERT - ${__TIMER:-__ERT}))"
  fi

  eval "$(powerline-go -cwd-max-depth 1 -jobs ${${(%):%j}:-0} -modules cwd,jobs -duration $__DURATION -error $__ERRCODE -shell zsh -eval -modules-right duration,node,docker,dotenv,kube,venv,git,exit)"
  export BASE_PROMPT=$PROMPT

  unset __TIMER
}

precmd_functions+=(powerline_precmd)

function vi-mode-prompt {
  case ${KEYMAP} in
    (vicmd)      echo -e "\\e[48;5;245m C \\e[0m" ;;
    (main|viins) echo -e "\\e[48;5;202m I \\e[0m" ;;
    (*)          echo -e "\\e[48;5;202m I \\e[0m" ;;
  esac
}

function zle-line-init zle-keymap-select {
  PS1="$(vi-mode-prompt)$BASE_PROMPT"
  zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select

setopt transient_rprompt