akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.68k stars 85 forks source link

[tmux-resurrect] Cache broken on restoring (Error `ble.sh: The keymap 'vi_imap' is empty.`) #109

Open RakibFiha opened 3 years ago

RakibFiha commented 3 years ago

ble version: 0.4.0-devel3+750ca38 Bash version: 5.0.17(1)-release (x86_64-pc-linux-gnu)

I am getting ble.sh: The keymap 'vi_imap' is empty. after restoring my tmux session, and ble.sh is not loading.

I am also unable to see any key press in the terminal, unless I do tput reset

RakibFiha commented 3 years ago

~I have went back to 0506df28baa6a and not getting this error.~

akinomyoga commented 3 years ago

I have went back to 0506df28baa6a and not getting this error.

Thank you for the report! Can you identify the commit where the problem starts by using binary search (or manual git bisect)?

RakibFiha commented 3 years ago

Weird!! After, rebuilding from latest master, it went away.

RakibFiha commented 3 years ago

Hmm, seems like, it only happens when tmux session is restored even for https://github.com/akinomyoga/ble.sh/commit/0506df28baa6ac54de6cb6650d2ad208b0c00190

I am using a plugin called tmux-resurrect with tpm.

akinomyoga commented 3 years ago

Weird!! After, rebuilding from latest master, it went away.

Ah, OK. I think it was because the keymap cache has been updated by switching the commit.

Actually, I recently experienced the same phenomena in my local testing once. I found that this is caused by an empty keymap cache file $_ble_base_cache/keymap.vi, but I couldn't find the reason why the file became empty and couldn't reproduce the same phenomena anymore. Now it seems you can reproduce the problem, I'd like to further collect the information.

Hmm, seems like, it only happens when tmux session is restored even for 0506df2

I am using a plugin called tmux-resurrect with tpm.

I'm actually not sure what tmux-resurrect does, but does it mean if you just reattach the tmux session without using tmux-resurrect, the problem doesn't reproduce?

RakibFiha commented 3 years ago

Persists tmux environment across system restarts.

tmux-resurrect allows to save a session, manually (prefix + ctr +s) or automatically at some interval. So, even after you kill that session, you can still get that session back (like panes, windows and so on). It makes it also possible to get the session back after reboot of machine.

akinomyoga commented 3 years ago

Thank you for the explanation. I'm looking at the manual of tmux-resurrect. Now I'm wondering if it tries to restore the Bash session as well (including the current directory, aliases, user-defined key-bindings, etc.) not only the tmux window layout? It says it restores the state of vi, emacs, etc. but doesn't mention bash which I think the most essential which is weird.

akinomyoga commented 3 years ago

Maybe it is different from the problem that I experienced before. I think I can try to set up tmux-resurrect tomorrow in my machine to see if the same problem reproduces. For now, could you see whether the file $_ble_base_cache/keymap.vi is empty when the problem is present?

$ ls -l "$_ble_base_cache/keymap.vi"
RakibFiha commented 3 years ago

Before resurrection

md5sum: 0b5037c79032706a9ae7858a3a920c7b ~/.cache/blesh/0.4/keymap.vi

not empty

After resurrection:

The error happens and nothing typed can be seen in the window. After tput reset the typing appears.

And, yes the ~/.cache/blesh/0.4/keymap.vi is empty. :)

akinomyoga commented 3 years ago

Thank you! OK... the cache file becomes indeed empty by tmux-resurrect. It's really puzzling that the cache file is affected by the resurrection... I'll try to find what's happening.

For the time being, If you want to soon use ble.sh, you can just delete the file $_ble_base_cache/keymap.vi every time when the problem started to happen.

akinomyoga commented 3 years ago

Hi, I have set up tmux-resurrect using tpm, saved a session with prefixC-s, and restored prefixC-r, but it just works without problems. I have questions:

RakibFiha commented 3 years ago

I actually cannot reproduce it anymore. Not sure why.

But, yesterday the steps mentioned at Q1 would reproduce it. I will try again tomorrow.

Q2: Does the problem occur without ~/.inputrc?

Removing inputrc also is not reproducing it.

akinomyoga commented 3 years ago

Hmm, heisenbug... Have you changed your shell configuration or system configuration or updated some softwares since you last reproduced the problem?

akinomyoga commented 3 years ago

I'm looking at code and thinking of possible causes.

akinomyoga commented 3 years ago

Hi, did the problem appeared again in your environment? It seems that the problem cannot be reproduced on my side. Nevertheless, I added a workaround for the phenomena of the vi_imap cache becoming empty in commit 560160b. Now ble.sh checks that the cache is non-empty before reading the cache file. This fix doesn't solve the root cause but is just a workaround for the resultant phenomena of the empty vi_imap cache, so possibly some other problems are still present. If you have noticed something additional, please let me know. Thank you!