Created
July 12, 2021 23:25
-
-
Save disco0/312d6c4bf829c070118c515fb1390b4d to your computer and use it in GitHub Desktop.
brew-install-vintage - Install a previous version of a homebrew formula
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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