dotfiles
dotfiles copied to clipboard
enable access to GNU coreutils man pages
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.
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.
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.
Could you move this to the .exports
file please?
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 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 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 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 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.
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, do you mind sharing this Python script? :)
https://gist.github.com/Tatsh/1afd6d68113ec7342d045321f1dc3402 See the write_aliases()
function