Skip to content

Instantly share code, notes, and snippets.

@cmsj
Last active April 28, 2019 13:38

Revisions

  1. cmsj revised this gist Jan 15, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions homegnu.sh
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,7 @@
    # * source /path/to/homegnu.sh
    # 3) (optional extra) build something fancy into your $PS1 to detect $__HOMEGNU is set, to let you know commands are different now
    # 4) Explore other packages that have gnubin paths: grep -rl gnubin /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/
    # 5) To undo Homegnu, either set your $PATH back to normal, or just spawn a new shell/terminal

    BREWROOT="/usr/local"
    GNUPATH=""
  2. cmsj revised this gist Jan 15, 2018. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions homegnu.sh
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,17 @@
    # This script will attempt to make your macOS system behave more like GNU for shell scripts
    # by diverting as many commands as possible, to the GNU versions, provided by Homebrew
    #
    # For most Homebrew tools, their presence in /usr/local/bin and that being in your $PATH
    # means you can use them as-is, but some tools appear with different names because macOS
    # already has such a tool (e.g. find(1)). These tools generally also have a `gnubin` path
    # which we can use to make them higher priority than the macOS equivalents.
    #
    # To use this:
    # 1) Install various GNU tools via homebrew, such as:
    # * coreutils
    # * gnu-getopt
    # * gnu-sed
    # * gawk
    # * gnu-tar
    # * gnu-time
    # * gnu-which
    @@ -15,6 +21,7 @@
    # 2) Load this script into your shell when you want to Go GNU:
    # * source /path/to/homegnu.sh
    # 3) (optional extra) build something fancy into your $PS1 to detect $__HOMEGNU is set, to let you know commands are different now
    # 4) Explore other packages that have gnubin paths: grep -rl gnubin /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/

    BREWROOT="/usr/local"
    GNUPATH=""
  3. cmsj revised this gist Jan 15, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion homegnu.sh
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,6 @@
    BREWROOT="/usr/local"
    GNUPATH=""

    #for gnubin in $(find -L ${BREWROOT}/opt -type d -name gnubin) ; do
    while read -r gnubin ; do
    GNUPATH="${gnubin}:${GNUPATH}"
    done < <(find -L "${BREWROOT}/opt" -type d -name gnubin)
  4. cmsj revised this gist Jan 15, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion homegnu.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/bin/bash
    #!/bin/echo Don't execute this script directly, source it into your shell.
    # This script will attempt to make your macOS system behave more like GNU for shell scripts
    # by diverting as many commands as possible, to the GNU versions, provided by Homebrew
    #
  5. cmsj created this gist Jan 15, 2018.
    28 changes: 28 additions & 0 deletions homegnu.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/bin/bash
    # This script will attempt to make your macOS system behave more like GNU for shell scripts
    # by diverting as many commands as possible, to the GNU versions, provided by Homebrew
    #
    # To use this:
    # 1) Install various GNU tools via homebrew, such as:
    # * coreutils
    # * gnu-getopt
    # * gnu-sed
    # * gnu-tar
    # * gnu-time
    # * gnu-which
    # * moreutils
    # * num-utils
    # 2) Load this script into your shell when you want to Go GNU:
    # * source /path/to/homegnu.sh
    # 3) (optional extra) build something fancy into your $PS1 to detect $__HOMEGNU is set, to let you know commands are different now

    BREWROOT="/usr/local"
    GNUPATH=""

    #for gnubin in $(find -L ${BREWROOT}/opt -type d -name gnubin) ; do
    while read -r gnubin ; do
    GNUPATH="${gnubin}:${GNUPATH}"
    done < <(find -L "${BREWROOT}/opt" -type d -name gnubin)

    export PATH="${GNUPATH}${PATH}"
    export __HOMEGNU=1