Skip to content

Instantly share code, notes, and snippets.

@andelink
Last active September 9, 2024 21:50
Show Gist options
  • Save andelink/5e648bda93a4ede398588fdf2010f794 to your computer and use it in GitHub Desktop.
Save andelink/5e648bda93a4ede398588fdf2010f794 to your computer and use it in GitHub Desktop.
Uncensored Homebrew fortune

Uncensored Homebrew fortune

Homebrew fortune doesn't include the full database of quotes. They removed the offensive category database several years ago:

You are greeted with an error when trying to use the offensive category:

❯ brew install fortune
❯ fortune -o
/opt/homebrew/Cellar/fortune/9708/share/games/fortunes/off: No such file or directory

Whether or not I will use the offensive quotes is irrelevant for me, personally. I'd just like the choice, without going through another package manager or hosting my own tap. This is the solution I've come up with.

Version-specific install

Generally, one can brew install https://raw.githubusercontent.com/... to install a specific formula version. But there have been many changes in the years since the offensive category was removed - notably a file rename and support for new architecture. Using a prior formula version may or may not work depending on your computer, and is not very future-proof.

Modified formula install

Warning

They are labeled offensive for a reason...

Instead we can download the latest formula definition and modify it to include the full database, and then pass that to brew install. Luckily, all that's required is the removal of the one line that references the OFFENSIVE make variable:

# This is the URL we want
❯ brew info fortune | awk '/From: / {print $2}'
https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/f/fortune.rb

# Download and delete the OFFENSIVE line
❯ brew info fortune \
  | awk '/From: / {print $2}' \
  | curl -sSL \
    --variable url@- \
    --expand-url '{{url:trim}}?raw=true' \
  | sed '/OFFENSIVE/d' \
  > /tmp/fortune.rb

# (Re)install our modified formula from source
❯ brew reinstall --formula --force --build-from-source /tmp/fortune.rb

# Check that it worked
❯ fortune -o
Ass, grass or gas... nobody rides for free!

# Pin our version to prevent unintentional future upgrades
❯ brew pin fortune

Same thing for cowsay

See: offensive content removal

❯ brew info cowsay | awk '/From: / {print $2}'
https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/c/cowsay.rb

# Download and delete the offensive lines
❯ brew info cowsay \
  | awk '/From: / {print $2}' \
  | curl -sSL \
    --variable url@- \
    --expand-url '{{url:trim}}?raw=true' \
  | sed '/offensive/,/end/d' \
  > /tmp/cowsay.rb

# (Re)install our modified formula from source
❯ brew reinstall --formula --force --build-from-source /tmp/cowsay.rb

# Check that it worked
❯ cowsay -l

# Pin our version to prevent unintentional future upgrades
❯ brew pin cowsay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment