cantino / mcfly

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

thread 'main' panicked at 'McFly error: Please ensure that MCFLY_HISTORY is set (environment variable not found)', src/settings.rs:301:29 #210

Closed RobBednark closed 2 years ago

RobBednark commented 2 years ago

tldr: it appears I need to set MCFLY_HISTORY=1 otherwise I get a panick. There's no mention of MCFLY_HISTORY in the docs, so I think it needs to be added.


Details: I just installed mcfly for the first time (brew tap cantino/mcfly ; brew install mcfly) I use bash and I added eval "$(mcfly init bash)" to the end of my .bashrc When I tried running it I got:

$ RUST_BACKTRACE=full mcfly search foo
thread 'main' panicked at 'McFly error: Please ensure that MCFLY_HISTORY is set (environment variable not found)', src/settings.rs:301:29
stack backtrace:
   0:        0x103b52cc6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::had87307b6abc1c9a
   1:        0x103a9210b - core::fmt::write::hf956bc155d959fe3
   2:        0x103b5250a - std::io::Write::write_fmt::h8329f2ae528d83ac
   3:        0x103b5231e - std::panicking::rust_panic_with_hook::h86c7505050d2207f
   4:        0x103b73dda - std::panicking::begin_panic_handler::{{closure}}::h61e80887dc228270
   5:        0x103b73d59 - std::sys_common::backtrace::__rust_end_short_backtrace::hf0f0a63f6b510120
   6:        0x103b73d15 - _rust_begin_unwind
   7:        0x103d0584f - std::panicking::begin_panic_fmt::h5b64fb3c8842dd24
   8:        0x103acc492 - mcfly::settings::Settings::parse_args::h78f0651dfa577c09
   9:        0x103a37933 - mcfly::main::h2938faa375b13096
  10:        0x103ae3156 - std::sys_common::backtrace::__rust_begin_short_backtrace::h6d5a4b6d5cd5b95d
  11:        0x103a3b666 - _main
  $ 

However, this worked: $ MCFLY_HISTORY=1 mcfly search foo

cantino commented 2 years ago

Hey @RobBednark, sorry to hear that. What shell are you using and how did you install mcfly? It sounds like it's not being sourced correctly on shell startup.

RobBednark commented 2 years ago

What shell are you using...?

I'm on MacOS using:

$ bash --version
GNU bash, version 5.1.4(1)-release (x86_64-apple-darwin19.6.0)

how did you install mcfly?

I installed it via brew install mcfly

$ mcfly --version
McFly 0.5.10
cantino commented 2 years ago

Thanks @RobBednark. Sorry for the delay.

1) What does echo $MCFLY_SESSION_ID output in your shell?

2) If you type some other shell command first, then run mcfly, does it work? I'm wondering if I have a bug where mcfly doesn't work until a command has been added to the history in your current session.

orhun commented 2 years ago

Having the same issue on bash:

$ eval $(mcfly init bash)

$ mcfly search x
thread 'main' panicked at 'McFly error: Please ensure that MCFLY_SESSION_ID contains a random session ID (environment variable not found)', src/settings.rs:285:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

$ MCFLY_HISTORY=1 MCFLY_SESSION_ID=2 mcfly search x # works

mcfly version: 0.6.0

cantino commented 2 years ago

I assume MCFLY_SESSION_ID isn't set for you?

orhun commented 2 years ago

I assume MCFLY_SESSION_ID isn't set for you?

Yes, it isn't set after I initialize mcfly with eval. However, if I do the following (on Arch Linux) it works:

$ source /usr/share/doc/mcfly/mcfly.bash
$ echo $MCFLY_SESSION_ID
OlKBqbEd98BAn2yfwQLhYd6R

Putting the eval statement in .bashrc also doesn't work for me. Weird.

emmahyde commented 2 years ago

same thing happening for me

cantino commented 2 years ago

All I can think of is that either [[ -t 0 ]] || return is returning in eval but not in source, or maybe somehow __MCFLY_LOADED is getting set. If you want to help debug, you could add some echo statements in /usr/share/doc/mcfly/mcfly.bash to help see how far it's getting into the file.

orhun commented 2 years ago

Having the same issue on bash:

$ eval $(mcfly init bash)

$ mcfly search x
thread 'main' panicked at 'McFly error: Please ensure that MCFLY_SESSION_ID contains a random session ID (environment variable not found)', src/settings.rs:285:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

$ MCFLY_HISTORY=1 MCFLY_SESSION_ID=2 mcfly search x # works

Okay I figured it out, I was missing double quotes 😮‍💨 This works:

$ eval "$(mcfly init bash)"

or

$ echo 'eval "$(mcfly init bash)"' >> ~/.bashrc
cantino commented 2 years ago

Oh I'm glad you figured it out!