Skip to content

Instantly share code, notes, and snippets.

@disco0
Created July 12, 2021 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disco0/312d6c4bf829c070118c515fb1390b4d to your computer and use it in GitHub Desktop.
Save disco0/312d6c4bf829c070118c515fb1390b4d to your computer and use it in GitHub Desktop.
brew-install-vintage - Install a previous version of a homebrew formula
#!/usr/bin/env zsh
###
# Installs a previous version of a homebrew formula.
#
# Based on https://cmichel.io/how-to-install-an-old-package-version-with-brew/
#
# @param $1 @ Formula Name
# @param $2 @ Version
##
function brew-install-vintage()
{
if ! (( $+commands[brew] ))
then
builtin print -Pu2 -- '%F{1}brew command not found in \\$PATH.%f'
return 2
fi
local formula_name=${1}
local target_version=${2}
if (( $#@ < 2 )) || [[ -z $formula_name || -z $target_version ]]
then
# (print help)
builtin print -Pu2 -- "%B%{${0}%}%b <formula-name> <formula-version>"
return 1
fi
# use $USER variable to mimick userName/repoName structure
# this does not actually create any git repositories
local extract_prefix=${USER}/local-
local tap_name=${extract_prefix}${formula_name}-${target_version//\./-}
# 1. create a new tap
# 2. extract into local tap
# 3. run brew install@version as usual
command brew tap-new ${tap_name} \
&& command brew extract --version=${target_version} ${formula_name} ${tap_name} \
&& command brew install ${formula_name}@${target_version}
}
# brew-install-vintage emscripten 2.0.17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment