Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Running GNU coreutils via Homebrew on your Mac? Here's a one-liner to get the manpages working!
# Short of learning how to actually configure OSX, here's a hacky way to use
# GNU manpages for programs that are GNU ones, and fallback to OSX manpages otherwise
alias man='_() { echo $1; man -M $(brew --prefix)/opt/coreutils/libexec/gnuman $1 1>/dev/null 2>&1; if [ "$?" -eq 0 ]; then man -M $(brew --prefix)/opt/coreutils/libexec/gnuman $1; else man $1; fi }; _'
@quickshiftin

This comment has been minimized.

Show comment Hide comment
@quickshiftin

quickshiftin Feb 21, 2014

Follow an article like this describing how to use Homebrew to setup GNU coreutils et al on your Mac.

Then when you want to spend less than a minute getting the manpages to work with both your new GNU programs and your Mac programs you still want to be able to use (like mdfind), paste this gist in your ~/.profile and away you go!

Owner

quickshiftin commented Feb 21, 2014

Follow an article like this describing how to use Homebrew to setup GNU coreutils et al on your Mac.

Then when you want to spend less than a minute getting the manpages to work with both your new GNU programs and your Mac programs you still want to be able to use (like mdfind), paste this gist in your ~/.profile and away you go!

@LeeMendelowitz

This comment has been minimized.

Show comment Hide comment
@LeeMendelowitz

LeeMendelowitz Oct 17, 2014

Thanks for this solution!

Thanks for this solution!

@liselorev

This comment has been minimized.

Show comment Hide comment
@liselorev

liselorev Oct 22, 2014

Additionally, if one wants to make it available system-wide, one could add the lines to
/etc/paths
/etc/manpaths
Where /usr/libexec/path_helper would include them.

    $> PA1="$(brew --prefix coreutil)/libexec/" ;
    $> : ; # expand slashes (for sed use)
    $> BINPA ="${PA1//\//\\/}gnubin" ;
    $> MANPA ="${PA1//\//\\/}gnuman" ;
    $> : ; # put as first line
    $> sudo sed -i'' -e '1s/^/'"${BINPA}"'\n/' /etc/paths ;
    $> sudo sed -i'' -e '1s/^/'"${MANPA}"'\n/' /etc/manpaths ;

Additionally, if one wants to make it available system-wide, one could add the lines to
/etc/paths
/etc/manpaths
Where /usr/libexec/path_helper would include them.

    $> PA1="$(brew --prefix coreutil)/libexec/" ;
    $> : ; # expand slashes (for sed use)
    $> BINPA ="${PA1//\//\\/}gnubin" ;
    $> MANPA ="${PA1//\//\\/}gnuman" ;
    $> : ; # put as first line
    $> sudo sed -i'' -e '1s/^/'"${BINPA}"'\n/' /etc/paths ;
    $> sudo sed -i'' -e '1s/^/'"${MANPA}"'\n/' /etc/manpaths ;
@StrikeW

This comment has been minimized.

Show comment Hide comment
@StrikeW

StrikeW Jan 24, 2015

This solution makes the [section] argument for man fail to work.
e.g:
man 2 read can not find the man page for read in section 2.

StrikeW commented Jan 24, 2015

This solution makes the [section] argument for man fail to work.
e.g:
man 2 read can not find the man page for read in section 2.

@ChrisCummins

This comment has been minimized.

Show comment Hide comment
@ChrisCummins

ChrisCummins Aug 1, 2015

Not one to settle for hacky work-arounds, I did a bit of googling and eventually found this solution to work for adding the gnu manpages:

  1. Open the file /etc/man.conf
  2. Add a line:
MANPATH_MAP /usr/local/opt/coreutils/libexec/gnubin /usr/local/opt/coreutils/libexec/gnuman

Hope that helps!

Not one to settle for hacky work-arounds, I did a bit of googling and eventually found this solution to work for adding the gnu manpages:

  1. Open the file /etc/man.conf
  2. Add a line:
MANPATH_MAP /usr/local/opt/coreutils/libexec/gnubin /usr/local/opt/coreutils/libexec/gnuman

Hope that helps!

@JacobDorman

This comment has been minimized.

Show comment Hide comment
@JacobDorman

JacobDorman Feb 15, 2016

Strange bug for me. Once i use man ... sudo is aliased to that function.

screen shot 2016-02-15 at 5 14 27 pm

Strange bug for me. Once i use man ... sudo is aliased to that function.

screen shot 2016-02-15 at 5 14 27 pm

@tasmo

This comment has been minimized.

Show comment Hide comment
@tasmo

tasmo Feb 24, 2016

@JacobDorman Do you use oh-my-zsh or prezto? There is an alias for sudo(!) which causes this failure. So try to comment out the line alias _='sudo' or add a line with unalias _ before the man alias.

tasmo commented Feb 24, 2016

@JacobDorman Do you use oh-my-zsh or prezto? There is an alias for sudo(!) which causes this failure. So try to comment out the line alias _='sudo' or add a line with unalias _ before the man alias.

@tasmo

This comment has been minimized.

Show comment Hide comment
@tasmo

tasmo Feb 24, 2016

The alias is not working with bash.

tasmo commented Feb 24, 2016

The alias is not working with bash.

@JacobDorman

This comment has been minimized.

Show comment Hide comment
@JacobDorman

JacobDorman Mar 6, 2016

@tasmo Ahh so there is. I never use that. unalias _ fixes the issue.

@tasmo Ahh so there is. I never use that. unalias _ fixes the issue.

@OJFord

This comment has been minimized.

Show comment Hide comment
@OJFord

OJFord Oct 8, 2016

What's wrong with just putting /usr/local/opt/coreutils/libexec/gnuman at the front of $MANPATH?

OJFord commented Oct 8, 2016

What's wrong with just putting /usr/local/opt/coreutils/libexec/gnuman at the front of $MANPATH?

@SystemDisc

This comment has been minimized.

Show comment Hide comment
@SystemDisc

SystemDisc Jan 28, 2017

I have the same question as @OJFord. Why not just export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"?

SystemDisc commented Jan 28, 2017

I have the same question as @OJFord. Why not just export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment