nvbn / thefuck

Magnificent app which corrects your previous console command.
MIT License
85.33k stars 3.43k forks source link

Shell startup time #859

Open leyyinad opened 5 years ago

leyyinad commented 5 years ago

Good morning everyone,

while profiling and optimizing my .zshrc, I just found that eval "$(thefuck --alias)" consumes quite some time (around 0.1s). I solved it by replacing it with

if command -v thefuck >/dev/null 2>&1; then
  fuck() {
    eval "$(thefuck --alias)" && fuck
  }
fi

This saves me around 100 sec when starting my zsh. Of course this might slow down running fuck, but it's clearly worth the price. Might this cause problems or did anybody figure a better way? I'm really not fond of spending 100ms on each shell invocation even on sessions when not using thefuck at all.

Any opinions on that?

Thank you! Daniel

chrisdepas commented 5 years ago

I've also found that eval "$(thefuck --alias)" is slow.

Slow enough I'd often end up executing udo apt install and the like because the first letter(s) were cut off.

I tried this instead (with bash) and it works perfectly, so I'll be using it from now on. Nice work.

+1 from me!

christf commented 1 year ago

Slightly different approach, I am caching the output of thefuck --alias for 5 days, so the slowdown only happens once in this time.

find ~/.bash_fuck -mtime +5 -delete
[[ -f ~/.bash_fuck ]] || eval $(thefuck --alias |tee ~/.bash_fuck)
eval $(cat ~/.bash_fuck )