cantino / mcfly

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

BUG : Sourcing zshrc file makes mcfly ineffective #339

Closed deekshithanand closed 1 year ago

deekshithanand commented 1 year ago

Hi there,

Issue : Mcfly works when the new terminal is opened first time. But if for some reason, if you source your rc file (zshrc in my case) , it makes mcfly stop working. I have provided a detailed evidence below. I can confirm that this issue is reproducible on macOS iterm2 as well.

Snippet used in my zshrc file:


# MCFLY configs
export MCFLY_RESULTS=20
export MCFLY_INTERFACE_VIEW=BOTTOM
export MCFLY_PROMPT="❯"
eval "$(mcfly init zsh)" 

Bug can be replicated as shown below : mcfly_bug

ahatzz11 commented 1 year ago

I have this exact same issue. I noticed that if I do a source ~/.zshrc then mcfly breaks on the source. If I run just a zsh, then mcfly seems to load properly.

.zshrc:

# Custom folder
ZSH_CUSTOM=~/.omz-custom

export ZSH="/Users/alexhatzenbuhler/.oh-my-zsh"
source $ZSH/oh-my-zsh.sh

eval "$(mcfly init zsh)"

When loading my terminal for the first time, mcfly works as expected. Once I source ~/.zshrc mcfly breaks. Here's another video of it happening:

image

cantino commented 1 year ago

It's odd that sourcing it again causes a problem. I think the lines at the top of mcfly.zsh may be the issue.

if [[ -o interactive ]] && [[ "$__MCFLY_LOADED" != "loaded" ]]; then
  __MCFLY_LOADED="loaded"

I wonder if they need to be

if [[ -o interactive ]] && [[ "$__MCFLY_LOADED" != "loaded" ]]; then
  export __MCFLY_LOADED="loaded"
cantino commented 1 year ago

Actually, it seems the solution is in the other direction, removing the entire $__MCFLY_LOADED concept fixes it for me:

# Ensure stdin is a tty
if [[ -o interactive ]]; then