Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Regarding

  if [[ -r "$(brew --prefix)/opt/mcfly/mcfly.zsh" ]]; then
    source "$(brew --prefix)/opt/mcfly/mcfly.zsh"
  fi
Tip: hardcode brew --prefix. It's /usr/local for most people anyway. brew is written in Ruby so invocations are expensive; brew --prefix takes ~30ms on my systems so the above snippet adds ~60ms to shell startup which is a complete waste. Add a couple of frivolous snippets like this and you have people complaining about slow startup.


Or as a compromise, `export BREW_PREFIX=$(brew --prefix)` somewhere nearer startup.


Optimization on that:

    if [[ -d /usr/local/opt/mcfly ]]; then
        export BREW_PREFIX=/usr/local
    else
        export BREW_PREFIX=$(brew --prefix)
    fi


I like what pyenv does when you do

    pyenv init
It prints the command for you. They could add the check there, generate the static path and then just print what they need to add hardcoded.

Edit,

For reference, this is what it prints on the different shells,

On ZSH,

    # Load pyenv automatically by appending
    # the following to ~/.zshrc:
    
    eval "$(pyenv init -)"
On Bash,

    # Load pyenv automatically by appending
    # the following to ~/.bash_profile:
    
    eval "$(pyenv init -)"
On Fish,

    # Load pyenv automatically by appending
    # the following to ~/.config/fish/config.fish:
    
    status --is-interactive; and source (pyenv init -|psub)


If every module you load does their own 30ms check, it might cut 60ms to 30ms at each call site but they add up just the same.


Of course.

I’m saying they print what you should add. I’m not saying have an init command that you run on your shell script on startup. I’m saying have an init command that tell you what to put.

I think the hardcoded approach by smichel17 with a fallback is a good one. Except that if you ran this command, it might print a different hardcoded path based on where it found the prefix to be at.


Thanks for the suggestion, I'll change that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: