GitHub 作為地表上最受歡迎原始碼代管平台 1,自然而然就會有工具利用它形成一個分享的生態圈,Vundle 及 Homebrew 就是經典的例子。
用 Vundle 安裝 vim plugin 時,只要簡單像下面加上一行 Plugin directive。
" .vimrc
Plugin "user/repo"
在 :PluginInstall
時就會去 GitHub 把 user/repo clone 在 .vim/bundle/user-repo
裡,再利用修改 vim runtimepath
的方法達到載入 plugin 的目的。
今天要介紹的 Homebrew Tap 2 也是利用 GitHub 來新增額外的 repo,用來分類與管理 formulae。
舉我剛剛建立的 Gasol/homebrew-formulae 為例:
首先在 GitHub 上建立好 repository,這邊要注意的是 repo 的名字一定要有 homebrew-
的前綴 3,否則 brew tap
會找不到。
shell> brew tap gasol/formulae
brew tap
會把 repo clone 在 /usr/local/Library/Taps/gasol/homebrew-formulae
shell> tree -CL 2 /usr/local/Library/Taps/
/usr/local/Library/Taps/
├── caskroom
│ └── homebrew-cask
├── gasol
│ └── homebrew-formulae
└── homebrew
├── homebrew-completions
├── homebrew-dupes
├── homebrew-php
└── homebrew-science
為了要 push formulae 上去 remote,所以我們要把 git 的 url 從 https 換成 ssh 的版本。
shell> cd /usr/local/Library/Taps/gasol/homebrew-formulae
shell /usr/local/Library/Taps/gasol/homebrew-formulae> git remote show origin
* remote origin
Fetch URL: https://github.com/Gasol/homebrew-formulae.git
Push URL: https://github.com/Gasol/homebrew-formulae.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
shell /usr/local/Library/Taps/gasol/homebrew-formulae> git remote set-url origin [email protected]:Gasol/homebrew-formulae.git
shell /usr/local/Library/Taps/gasol/homebrew-formulae> git remote show origin
* remote origin
Fetch URL: [email protected]:Gasol/homebrew-formulae.git
Push URL: [email protected]:Gasol/homebrew-formulae.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
之後就可以把自已建立的 formulae commit 進 repo 後再 push 上 GitHub。
shell /usr/local/Library/Taps/gasol/homebrew-formulae> git push -u origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 485 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:Gasol/homebrew-formulae.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
舉凡官方不收或是有 license 疑慮的 formulae 變可透過 Homebrew Tap 的方式來自已管理。