Skip to content

Instantly share code, notes, and snippets.

@manoelcampos
Last active March 27, 2020 12:33
Show Gist options
  • Save manoelcampos/dd52a84adcfbaf3eda8f8154cfb86c30 to your computer and use it in GitHub Desktop.
Save manoelcampos/dd52a84adcfbaf3eda8f8154cfb86c30 to your computer and use it in GitHub Desktop.
A shell script to run macOS homebrew as if it was the Debian/Ubuntu's apt-get command, just because "why not?" 😂
#!/bin/bash
# Runs macOS homebrew as if it was the Debian/Ubuntu's apt-get command,
# just because "why not?"
# Usage:
# sudo apt-get parameters
# or apt-get parameters
# Example: sudo apt-get install git
#
# Move the script to /usr/local/bin
# Although it's possible to run apt-get just as apt on Debian/Ubuntu,
# if you have Java installed in your macOS, naming this script as "apt" may not work.
COMMAND="brew $@"
if [[ $SUDO_USER == "" ]]; then
# If sudo is not used to run the script (and brew has to be called without it),
# runs the brew command with the parameters given to the script, using the current user
$COMMAND
else
# If sudo was used to run the script,
# runs the brew command with the parameters given to the script, using the user that called sudo
sudo -u "$SUDO_USER" $COMMAND
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment