From 18f3159626278fc3b8182de1557d4b89488ecd74 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 29 Feb 2024 19:42:09 -0600 Subject: [PATCH] Add View The Source For A Brew Formula as a Unix TIL --- README.md | 3 +- unix/view-the-source-for-a-brew-formula.md | 53 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 unix/view-the-source-for-a-brew-formula.md diff --git a/README.md b/README.md index d3facbe..10e3914 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1384 TILs and counting..._ +_1385 TILs and counting..._ --- @@ -1410,6 +1410,7 @@ _1384 TILs and counting..._ - [Use fzf To Change Directories](unix/use-fzf-to-change-directories.md) - [Use Regex Pattern Matching With Grep](unix/use-regex-pattern-matching-with-grep.md) - [View A Web Page In The Terminal](unix/view-a-web-page-in-the-terminal.md) +- [View The Source For A Brew Formula](unix/view-the-source-for-a-brew-formula.md) - [Watch The Difference](unix/watch-the-difference.md) - [Watch This Run Repeatedly](unix/watch-this-run-repeatedly.md) - [Where Are The Binaries?](unix/where-are-the-binaries.md) diff --git a/unix/view-the-source-for-a-brew-formula.md b/unix/view-the-source-for-a-brew-formula.md new file mode 100644 index 0000000..01eb1e9 --- /dev/null +++ b/unix/view-the-source-for-a-brew-formula.md @@ -0,0 +1,53 @@ +# View The Source For A Brew Formula + +[Homebrew](https://brew.sh/) uses formulas to know how to install things. If +you want to see what a given thing's formula file (written in Ruby) looks like, +there are two ways to get at it. + +If you already have the thing installed, the formula is available on your +machine. You can `cat` it to stdout with `brew cat`. + +```bash +❯ brew cat bat +``` + +Here is what `bat` looks like: + +```ruby +class Bat < Formula + desc "Clone of cat(1) with syntax highlighting and Git integration" + homepage "https://github.com/sharkdp/bat" + url "https://github.com/sharkdp/bat/archive/v0.17.1.tar.gz" + sha256 "16d39414e8a3b80d890cfdbca6c0e6ff280058397f4a3066c37e0998985d87c4" + license "Apache-2.0" + + depends_on "rust" => :build + + uses_from_macos "zlib" + + def install + ENV["SHELL_COMPLETIONS_DIR"] = buildpath + system "cargo", "install", *std_cargo_args + + assets_dir = Dir["target/release/build/bat-*/out/assets"].first + man1.install "#{assets_dir}/manual/bat.1" + fish_completion.install "#{assets_dir}/completions/bat.fish" + zsh_completion.install "#{assets_dir}/completions/bat.zsh" => "_bat" + end + + test do + pdf = test_fixtures("test.pdf") + output = shell_output("#{bin}/bat #{pdf} --color=never") + assert_match "Homebrew test", output + end +end +``` + +If you don't have the thing installed, you'll have to access the formula +remotely. + +```bash +❯ brew info --github bat +``` + +This will open up the formula on GitHub in your default browser.