dotfiles icon indicating copy to clipboard operation
dotfiles copied to clipboard

enable access to GNU coreutils man pages

Open asafch opened this issue 7 years ago • 11 comments

brew.sh will install coreutils, but doesn't configure .bash_profile to enable access to their man pages. This is fixed with defining $MANPATH and exporting it.

asafch avatar Aug 10 '16 19:08 asafch

Well, I don't know much about bash scripts. It seems like a good idea, but then I'd suggest going over all files and fixing them like this - there are other files that rely on the user manually inserting some kind of line.

asafch avatar Aug 11 '16 14:08 asafch

If a user opts to not install the coreutils, then this avoids bash tripping up during its sourcing of .bash_profile, as the condition will be false. A number of things in these dot files do something similar.

jeffbyrnes avatar Aug 11 '16 15:08 jeffbyrnes

Could you move this to the .exports file please?

mathiasbynens avatar Aug 11 '16 15:08 mathiasbynens

I can, but I don't know how to amend the pull request to consider it. Will it happen automatically if I amend the commit locally and then push it to GH? 😬

asafch avatar Aug 11 '16 15:08 asafch

@asafch Yeah, it will!

Please use something like this:

if which brew &> /dev/null && [ -d "$(brew --prefix coreutils)/libexec/gnubin" ]; then
    export PATH="$(brew --prefix coreutils)/libexec/gnubin:${PATH}";
    export MANPATH="$(brew --prefix coreutils)/libexec/gnuman:${MANPATH}";
fi;

Thanks.

mathiasbynens avatar Aug 11 '16 16:08 mathiasbynens

@mathiasbynens I tried this on my mac, it results in a slow startup of the terminal (~1 sec) instead of near instant when I just export. Could this be due to the conditional you suggested?

asafch avatar Aug 11 '16 16:08 asafch

@asafch probably, since brew --prefix coreutils takes ~0.3s on my Mac with SSD, and this snippet runs this command 3x.

$ time brew --prefix coreutils
/usr/local/opt/coreutils
brew --prefix coreutils  0.24s user 0.11s system 97% cpu 0.359 total

You can minimize the overhead by running this only once and "caching" the results, like this:

if which brew &> /dev/null; then
    local brew_prefix=$(brew --prefix coreutils)
    if [[ -d "${brew_prefix}/libexec/gnubin" ]]; then
        export PATH="${brew_prefix}/libexec/gnubin:${PATH}"
        export MANPATH="${brew_prefix}/libexec/gnuman:${MANPATH}"
    fi
fi

dserodio avatar Aug 11 '16 17:08 dserodio

@dserodio Thanks, great tip! I wonder if we could use this caching in other files to further speed-up the terminal startup. @mathiasbynens you're free to merge.

asafch avatar Aug 11 '16 17:08 asafch

I rarely do that kind of conditional anymore in any my dot files. I generate them with a script I wrote in Python that does these conditionals (and run it every time I pull). You don't change your system a whole lot and these conditionals really do add up in startup time, so I think the check is not worth it for every single terminal startup.

Tatsh avatar Aug 11 '16 22:08 Tatsh

@Tatsh, do you mind sharing this Python script? :)

dserodio avatar Aug 16 '16 18:08 dserodio

https://gist.github.com/Tatsh/1afd6d68113ec7342d045321f1dc3402 See the write_aliases() function

Tatsh avatar Aug 16 '16 19:08 Tatsh