Skip to content

Commit

Permalink
start homebrew tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
chantastic committed Aug 15, 2024
1 parent d1c738f commit f544421
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 61 deletions.
45 changes: 45 additions & 0 deletions chan.dev/src/content/guide_steps/homebrew/01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Dump your dependencies
slug: homebrew/dump-your-deps
---

Homebrew has command that will export a manifest of brew-installed packages.

```sh
brew bundle dump
```

The result is a `Brewfile` that looks like this:

```sh title="~/Brewfile"
tap "buo/cask-upgrade"
tap "candid82/brew"
tap "homebrew/bundle"
tap "homebrew/services"
brew "mas"
brew "neovim"
brew "node"
brew "node@20"
cask "font-jetbrains-mono-nerd-font"
cask "visual-studio-code"
vscode "esbenp.prettier-vscode"
vscode "supermaven.supermaven"
```

<!-- TODO: add mas to example -->

The `Brewfile` is created in the directory where you run the command.
But you can specify both file name and path with the `--file="~/some/path/my-brewfile"` option.

```sh
brew bundle dump --file="~/some/path/my-brewfile""
```
_Note that `brew bundle` commansd assume the file name `Brewfile`. So customizing the file name will required that all commands include the `--file` option, indifferent to file system location._
---
Congratulations.
You now have a manifest of installed software on your system.
<!-- TODO: possible appendixes: "tap, brew, cask, mas, and whale. what do they mean? anatomy of brewfile", "adding Brewfile to dotfiles (with symlinc)", "using the ---global flag to run brew bundle from anywhere", "installing from multiple brewfiles" -->
16 changes: 16 additions & 0 deletions chan.dev/src/content/guide_steps/homebrew/02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Bundling from Brewfiles
slug: homebrew/bundling-from-brewfiles
---

If you've used the default name of `Brewfile`, you can run the `brew bundle` command in that directory.

```sh
brew bundle
```

And if you want to bundle from a specific file, use the `--file` flag.

```sh
brew bundle --file=~/.dotfiles/Brewfile
```
45 changes: 45 additions & 0 deletions chan.dev/src/content/guide_steps/homebrew/03.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Conditionally bundle apps with environment variables
slug: homebrew/conditional-dependencies
---

Brew bundle allows for conditional loading of dependencies, using environmental variables.

As an examples, I use different versions of node on my work and personal machines.

If want, I can always install the latest version of Node. But also install the LTS version on my work machine.

```sh file="Brewfile"
brew "node"
brew "node@20" if [[ $MACHINE != "work" ]]
```
To proc this, I need to set an environment variable when running the command:
```sh
MACHINE=work brew bundle
```
<!-- TODO: test this command -->
## Inverting the command with unless
The Brewfile DSL also offers an `unless` keyword.
This is identical to `!=` above.
Use `unless`, if you think natural language reads better than code.
```sh file="Brewfile"
cask "arc" unless [[ $MACHINE == "work" ]]
```
## Next steps
I have a strong opinions about how to manage machine-specific environment variables. See the appendix on environment variables in the paid material for details.
## Next chapters to write
- understanding brewfile
- mas
- docker (whale)
74 changes: 13 additions & 61 deletions chan.dev/src/content/guide_steps/homebrew/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,29 @@
title: Homebrew
---

## Installation
Never setup another Mac.

Follow the up-to-date instructions on the site.
In just three years, I've had to provision seven Macs.

## Install terminal applications
I upgraded my personal mac, was laid off from one company, setup up an intermediate machine, then promptly joined aother company, to experience a corrupt drive two months in…

```sh
brew install neovim
```
It's been an adventure.

## Install GUI apps with Cask
Somewhere along the path, I got wise and learned how use Homebrew to provision a Mac with one line of code.

```sh
brew install --cask visual-studio-code
```
This guide will help you do the same.
But it's not for everyone.

## Install fonts with cask
This isn't a Homebrew tutorial.
I assume you have it setup and have already installed a package.

```sh
brew install --cask font-jetbrains-mono-nerd-font
```
I assume that you're already using Homebrew to install packages. But you haven't explored advanced features for system provisioning.

## Create a Brewfile from installed apps
Let's get into it.

```sh
brew bundle dump
```
chan

This will create a `Brewfile` in your current directory.
You can control the output file with the `--file` flag.

```sh
brew bundle dump --file=~/.dotfiles/Brewfile
```

## Install Visual Studio Code extensions in Brewfiles

```txt file="Brewfile"
vscode "asvetliakov.vscode-neovim"
```

## Bundle apps from Brewfile

If you've used the default name of `Brewfile`, you can run the `brew bundle` command in that directory.

```sh
brew bundle
```

And if you want to bundle from a specific file, use the `--file` flag.

```sh
brew bundle --file=~/.dotfiles/Brewfile
```

## Conditionally bundle apps with environment variables

```txt file="Brewfile"
cask "arc" if [[ $MACHINE != "work" ]]
```

You can also use `unless`, if you think natural language reads better than code.

```txt file="Brewfile"
cask "arc" unless [[ $MACHINE == "work" ]]
```

## Set machine variables in `.zshenv`

It's my preference to set variables for these types of checks in `.zshenv`.
I do not track this file in my my shared dotfiles. So it remains unique to each machine.
---

## References

Expand Down
24 changes: 24 additions & 0 deletions chan.dev/src/content/guide_steps/homebrew/xx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: 'Appendix A: Basic Usage'
slug: homebrew/basics
---

If you're new to Homebrew, here are a few basics for adding command line applications, GUI applications, and fonts.

## Install command line applications

```sh
brew install neovim
```

## Install GUI apps with Cask

```sh
brew install --cask visual-studio-code
```

## Install fonts with cask

```sh
brew install --cask font-jetbrains-mono-nerd-font
```
24 changes: 24 additions & 0 deletions chan.dev/src/content/guide_steps/homebrew/xxx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: 'Appendix: Storing machine-specific environment variables'
slug: 'homebrew/env-variables'
---

ZSHELL is the default shell in MacOS.

And there are several dotfiles it makes use of for very different needs.

This isn't a `ZSHELL` course. So I'll get to the point but leave helpful references.

<!-- link to docs on zsh -->

## Use .zshenv to store machine-specific envs

The best file for machine-spcefic inv variables `.zshenv`.

At to keep in machine-specific, I make sure that this file is never saved in my [`.dotfiles`](https://chantastic/.dotfiles) with this line in git.

```txt file=".gitignore"
zshenv
```

<!-- pitch course on managing dotfiles -->

0 comments on commit f544421

Please sign in to comment.