romkatv / powerlevel10k

A Zsh theme
MIT License
46.53k stars 2.19k forks source link

zsh: bad math expression: illegal character: ^[ #856

Open tmpm697 opened 4 years ago

tmpm697 commented 4 years ago

Steps:

1. cd to an folder
2. press and hold ctrl-c
3. observer the error: ^C^C^Czsh: bad math expression: illegal character: ^[

Why does it happen?

romkatv commented 4 years ago

Please run the following command:

( 
  emulate -L zsh -o err_return
  local tmp
  tmp="$(mktemp -d ${TMPDIR:-/tmp}/p10k.XXXXXXXXXX)"
  {
    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $tmp/powerlevel10k
    >$tmp/.zshrc <<\END
POWERLEVEL9K_MODE=ascii
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(prompt_char)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
source $ZDOTDIR/powerlevel10k/powerlevel10k.zsh-theme
END
    ZDOTDIR=$tmp zsh
  } always {
    cd /
    command rm -rf -- $tmp
  }
)

When prompt appears, press and hold Ctrl+C.

Do you get an error saying "bad math expression"?

tmpm697 commented 4 years ago

No, I don't get any errors at all. Steps:

1. cd to a folder
2. paste to terminal: ( 
  emulate -L zsh -o err_return
  local tmp
  tmp="$(mktemp -d ${TMPDIR:-/tmp}/p10k.XXXXXXXXXX)"
  {
    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $tmp/powerlevel10k
    >$tmp/.zshrc <<\END
POWERLEVEL9K_MODE=ascii
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(prompt_char)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
source $ZDOTDIR/powerlevel10k/powerlevel10k.zsh-theme
END
    ZDOTDIR=$tmp zsh
  } always {
    cd /
    command rm -rf -- $tmp
  }
)
3. press and hold ctrl-c.
4. observer no errors.
romkatv commented 4 years ago

This command simply repeats your own instructions. If it doesn't reproduce the error, it means something is missing from your instructions that is required to reproduce it.

How do I reproduce the error?

tmpm697 commented 4 years ago

Steps:

1. vi .zshenv
ZDOTDIR=$HOME/.config/zsh
2. vi ~/.config/zsh/.zshrc
[[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]] && . "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" # load instant prompt
source $ZDOTDIR/plugins/powerlevel10k/powerlevel10k.zsh-theme
[[ ! -f ${ZDOTDIR}/.p10k.zsh ]] || . ${ZDOTDIR}/.p10k.zsh
3. press and hold ctrl-c in a new shell
4. observer the error: ^Czsh: bad math expression: illegal character: ^[
romkatv commented 4 years ago

Cannot reproduce with these instructions. Can you?

  1. Run this command:
( 
  emulate -L zsh -o err_return
  local tmp
  tmp="$(mktemp -d ${TMPDIR:-/tmp}/p10k.XXXXXXXXXX)"
  {
    local zd=$tmp/.config/zsh
    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $zd/plugins/powerlevel10k

    >$tmp/.zshenv <<\END
ZDOTDIR=$ZDOTDIR/.config/zsh
END

    >$zd/.zshrc <<\END
[[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]] &&
  . "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
source $ZDOTDIR/plugins/powerlevel10k/powerlevel10k.zsh-theme
[[ ! -f ${ZDOTDIR}/.p10k.zsh ]] || . ${ZDOTDIR}/.p10k.zsh
END

    >$zd/.p10k.zsh <<\END
POWERLEVEL9K_MODE=ascii
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(prompt_char)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
END

    ZDOTDIR=$tmp zsh
  } always {
    cd /
    command rm -rf -- $tmp
  }
)
  1. When prompt appears, press and hold Ctrl+C.

If you cannot reproduce it this way, it means your instructions are missing something that is necessary to reproduce the error. Please list complete instructions. These instructions must not refer to any files that I don't have on my machine. Try following your own instructions to reproduce before posting them.

romkatv commented 4 years ago

I couldn't reproduce it by following your instructions. Then I wrote a script that spams SIGINT and finally reproduced it.

Is there a reason you press and hold Ctrl+C? Knowing why you are doing it will allow me to prioritize this issue.

tmpm697 commented 4 years ago

There's no reason why I spam ctrl-c at all but I just want to give a test how powerlevel10k can endure it and what its behavior if I spam ctrl-c.

As ctrl-c is one of my primary key to exit most of program beside with ctrl-q, occasionally I know I will press more than one as also I use pretty high rate of key response in Xorg -- this I think why I can produce it easily.

romkatv commented 4 years ago

Thanks for the reply.

When you spam Ctrl+C into shell, lots and lots of things break. You are basically interrupting plugins at random places. Having broken prompt is not the worst thing that can happen. Once you interrupt some function before it has a chance to restore invariants tied to global parameters, there is no telling what will happen.

I'll keep this issue open for a while. I consider it low priority. Not sure if I'll get to looking at it or not.

tmpm697 commented 4 years ago

I notice the density/gaps between prompt change when issue happens:

before:

>      # first prompt
>      # after first ctrl-c
>      # after seconds ctrl-c
>

after:

>      # first prompt
>      # after first ctrl-c, issue happens after this
^C^C^C^Czsh: bad math expression: illegal character: ^[

%

>      # after seconds ctrl-c
%

>
%

So basically it has %\n and \n after issue happens, ^C^C^C^Czsh: bad math expression: illegal character: ^[ and \n and %\n and \n when issue happens.

matorchio commented 4 years ago

This is also happening to me after upgrading from zsh 5.3 to zsh 5.8 (x86_64-apple-darwin18.7.0). After running some manual tests I noticed that zsh 5.3 was responding much faster to Ctrl+C and was able to endure spamming the command much longer (it breaks after some time too). This is quite annoying since I usually need to spam a couple of Ctrl+C to kill some of my processes.

romkatv commented 4 years ago

FYI: I don’t intend to look into this issue

tmpm697 commented 4 years ago

@romkatv: Do you have any idea why this issue can happen?, I'd like to trace it a bit when I have free time.

romkatv commented 4 years ago

Zsh gets SIGINT in the middle of precmd or prompt expansion.