cantino / mcfly

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

Panic when using mcfly search in fish #342

Closed manfredlotz closed 1 year ago

manfredlotz commented 1 year ago

Trying out mcfly in fish shell and get a panic.

mcfly 0.8.0 fish, version 3.6.0

I have

  mcfly init fish | source

  set -gx MCFLY_FUZZY 2
  set -gx MCFLY_RESULTS 50

at the end of ~/.config/fish/config.fish

env | grep MCFLY gives

MCFLY_FUZZY=2
MCFLY_SESSION_ID=jJK3mNhLoUXBArCOzAv2rPcO
MCFLY_HISTFILE=/home/manfred/.local/share/fish/fish_history
MCFLY_RESULTS=50

Now running mcfly search something I get

thread 'main' panicked at 'McFly error: Please ensure that MCFLY_HISTORY is set (environment variable not found)', src/settings.rs:177:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
cantino commented 1 year ago

Hey @manfredlotz, sorry you're having issues with mcfly. I honestly don't know why you're getting that error if MCFLY_HISTORY is set. I don't use fish myself. My config.fish for testing just includes

mcfly init fish | source
mcfly_key_bindings
manfredlotz commented 1 year ago

The problem is that MCFLY_HISTORY is not set as I showed above. Simply, because mcfly init fish | source doesn't set it.

I find the line

# We don't need a MCFLY_HISTORY file because we can get the last command in fish_postexec.

in the output of mcfly init fish.

So, the conclusion is that something is inconsistent here.

cantino commented 1 year ago

Okay, so what's weird here is that it first tries to call cli.mcfly_history, which should have been set by

set -g __MCFLY_CMD $MCFLY_PATH --mcfly_history /dev/null --history_format fish

It's being set to /dev/null but it is providing that as a command line argument, so the code in src/settings.rs:177:25 should never have run.

What happens if you set MCFLY_DEBUG to true in a new shell? Here's what I see:

andrew@Andrews-Mac ~/p/r/mcfly (master)> fish --version
fish, version 3.6.1
mcfly.fish: Run eval target/debug/mcfly --mcfly_history /dev/null --history_format fish add --exit $last_status --old-dir $__MCFLY_OLD_PWD -- $argv[1]
andrew@Andrews-Mac ~/p/r/mcfly (master)>
manfredlotz commented 1 year ago

❯ set MCFLY_DEBUG true yields

mcfly.fish: Run eval /usr/bin/mcfly --mcfly_history /dev/null --history_format fish add --exit $last_status --old-dir $__MCFLY_OLD_PWD -- $argv[1]

Ok, here I didn't have a problem anyway.

Even with setting MCFLY_DEBUG to true the search

❯ mcfly search bla yields

thread 'main' panicked at 'McFly error: Please ensure that MCFLY_HISTORY is set (environment variable not found)', src/settings.rs:177:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
mcfly.fish: Run eval /usr/bin/mcfly --mcfly_history /dev/null --history_format fish add --exit $last_status --old-dir $__MCFLY_OLD_PWD -- $argv[1]

Of course, if I do this mcfly --mcfly_history /dev/null search bla then there is no problem

cantino commented 1 year ago

Oh! mcfly search isn't really intended to be executed directly. The intended use is for mcfly to be executed via Ctrl-R in the shell.

manfredlotz commented 1 year ago

ok, understand.