cantino / mcfly

Fly through your shell history. Great Scott!
MIT License
6.77k stars 176 forks source link

Sourcing .zshrc didn't rebind Ctrl+R for me, had to restart kitty #239

Closed gthb closed 1 year ago

gthb commented 2 years ago

New to McFly, I followed the installation instructions in the readme (in Kitty, running zsh), and in this line:

Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

... I tried the former, just sourcing .zshrc. But Ctrl+R still just invoked the familiar old bck-i-search experience.

I tried to troubleshoot that for a while, hunt down where the relevant bindkey was invoked etc., but in the end I gave up and restarted Kitty. After that, Ctrl+R invoked McFly as expected.

Is it expected behavior that sourcing .zshrc will not suffice in some circumstances? Then maybe change that line to say something like “Run . ~/.bashrc [...] to reload your shell configuration, and then try Ctrl+R. If that doesn't bring up McFly, restart your terminal emulator”.

But if sourcing shell config is always supposed to be enough, then maybe there's some initialization problem to hunt down?

cantino commented 2 years ago

I wonder if your .zshrc has some code that exits early if it has been sourced before. In general I just restart the shell when installing.

gthb commented 2 years ago

Tried to test that by commenting out the eval line, starting a new terminal in kitty, verifying that Ctrl-R was not invoking McFly, then uncommenting the eval line and surrounding it by echos:

echo 'evaling mcfly'
eval "$(mcfly init zsh)"
echo 'done evaling mcfly'

and then sourcing .zshrc:

$ source ~/.zshrc
evaling mcfly
done evaling mcfly

so it did run ... but, uh, then McFly worked. So this failed to reproduce. 😞 I.e. I can't rule out that what you described was the problem when I got the problem.

I wonder if this had to do with whatever shenanigans underlie PowerLevel10k's “instant prompt” feature (which, yes, I have enabled at the top of my .zshrc). Maybe that causes some of .zshrc not to run (though their description of the feature doesn't sound like it should).

I notice that they recommend not to source .zshrc at all:

Weird things happen after typing source ~/.zshrc

It's almost always a bad idea to run source ~/.zshrc, whether you are using Powerlevel10k or not. This command may result in random errors, misbehaving code and progressive slowdown of Zsh.

If you've made changes to ~/.zshrc or to files sourced by it, restart Zsh to apply them. The most reliable way to do this is to type exit and then start a new Zsh session. You can also use exec zsh. While not exactly equivalent to complete Zsh restart, this command is much more reliable than source ~/.zshrc.

... which I guess gels with what you said,

In general I just restart the shell

cantino commented 2 years ago

Thanks for testing it out. I do suspect it was instant prompt or something similar. 🤷

tombh commented 2 years ago

As mentioned in #254, a quick fix for this is to, instead of eval "$(mcfly init zsh)", just use source <(mcfly init zsh).

cantino commented 1 year ago

I believe this is fixed now.