Skip to content

Instantly share code, notes, and snippets.

@nickccm1122
Last active March 7, 2024 07:00
Show Gist options
  • Save nickccm1122/a39517e3ebf58e49df0a9bc589a9c2db to your computer and use it in GitHub Desktop.
Save nickccm1122/a39517e3ebf58e49df0a9bc589a9c2db to your computer and use it in GitHub Desktop.
script to replace macos legacy cli
#!/usr/bin/sh
###################################################
# Check if the brew path of the item exists
# then run brew install if not exits
# set the PATH and MANPATH for each item
###################################################
# check if brew is installed
if ! [ -x "$(command -v brew)" ]; then
echo 'Error: brew is not installed.' >&2
exit 1
fi
BREW_PATH="$(brew --prefix)/opt/"
# coreutils
BREW_ITEM_PATH="${BREW_PATH}coreutils"
if ! [ -d "$BREW_ITEM_PATH" ]; then
echo "installing coreutils..."
brew install coreutils
fi
export PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH"
export MANPATH="$(brew --prefix)/opt/coreutils/libexec/gnuman:$MANPATH"
# findutils
BREW_ITEM_PATH="${BREW_PATH}findutils"
if ! [ -d "$BREW_ITEM_PATH" ]; then
echo "installing findutils..."
brew install findutils
fi
export PATH="$(brew --prefix)/opt/findutils/libexec/gnubin:$PATH"
export MANPATH="$(brew --prefix)/opt/findutils/libexec/gnuman:$MANPATH"
# diffutils
BREW_ITEM_PATH="${BREW_PATH}diffutils"
if ! [ -d "$BREW_ITEM_PATH" ]; then
echo "installing diffutils..."
brew install diffutils
fi
export PATH="$(brew --prefix)/opt/diffutils/bin:$PATH"
export PATH="$(brew --prefix)/opt/diffutils/share/man:$PATH"
# gawk
BREW_ITEM_PATH="${BREW_PATH}gawk"
if ! [ -d "$BREW_ITEM_PATH" ]; then
echo "installing gawk..."
brew install gawk
fi
export PATH="$(brew --prefix)/opt/gawk/libexec/gnubin:$PATH"
export MANPATH="$(brew --prefix)/opt/gawk/libexec/gnuman:$MANPATH"
# gnu-sed
BREW_ITEM_PATH="${BREW_PATH}gnu-sed"
if ! [ -d "$BREW_ITEM_PATH" ]; then
echo "installing gnu-sed..."
brew install gnu-sed
fi
export PATH="$(brew --prefix)/opt/gnu-sed/libexec/gnubin:$PATH"
export MANPATH="$(brew --prefix)/opt/gnu-sed/libexec/gnuman:$MANPATH"
# gnu-tar
BREW_ITEM_PATH="${BREW_PATH}gnu-tar"
if ! [ -d "$BREW_ITEM_PATH" ]; then
echo "installing gnu-tar..."
brew install gnu-tar
fi
export PATH="$(brew --prefix)/opt/gnu-tar/libexec/gnubin:$PATH"
export MANPATH="$(brew --prefix)/opt/gnu-tar/libexec/gnuman:$MANPATH"
# gnu-which
BREW_ITEM_PATH="${BREW_PATH}gnu-which"
if ! [ -d "$BREW_ITEM_PATH" ]; then
echo "installing gnu-which..."
brew install gnu-which
fi
export PATH="$(brew --prefix)/opt/gnu-which/libexec/gnubin:$PATH"
export MANPATH="$(brew --prefix)/opt/gnu-which/libexec/gnuman:$MANPATH"
# grep
BREW_ITEM_PATH="${BREW_PATH}grep"
if ! [ -d "$BREW_ITEM_PATH" ]; then
echo "installing grep..."
brew install grep
fi
export PATH="$(brew --prefix)/opt/grep/libexec/gnubin:$PATH"
export MANPATH="$(brew --prefix)/opt/grep/libexec/gnuman:$MANPATH"
# less
BREW_ITEM_PATH="${BREW_PATH}less"
if ! [ -d "$BREW_ITEM_PATH" ]; then
echo "installing less..."
brew install less
fi
export PATH="$(brew --prefix)/opt/less/bin:$PATH"
export MANPATH="$(brew --prefix)/opt/less/share/man:$MANPATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment