Refactor MacOS.
Refactor MacOS.

* call `xcode-select` once and cache the result
* reuse functions where appropriate

vitorgalvao/brew,mistydemeo/homebrew,palxex/brew,MikeMcQuaid/brew,EricFromCanada/brew,mgrimes/brew,staticfloat/brew,palxex/brew,Linuxbrew/brew,muellermartin/dist,AnastasiaSulyagina/brew,hanxue/linuxbrew,claui/brew,muellermartin/dist,konqui/brew,konqui/brew,EricFromCanada/brew,palxex/brew,muellermartin/dist,mistydemeo/homebrew,claui/brew,reitermarkus/brew,claui/brew,DomT4/brew,amar-laksh/brew_sudo,toonetown/homebrew,AnastasiaSulyagina/brew,nandub/brew,toonetown/homebrew,Homebrew/brew,Homebrew/brew,DomT4/brew,reelsense/brew,MikeMcQuaid/brew,sjackman/homebrew,reitermarkus/brew,Linuxbrew/brew,jmsundar/brew,zmwangx/brew,JCount/brew,EricFromCanada/brew,mahori/brew,ilovezfs/brew,mgrimes/brew,ilovezfs/brew,nandub/brew,MikeMcQuaid/brew,rwhogg/brew,DomT4/brew,MikeMcQuaid/brew,nandub/brew,vitorgalvao/brew,reitermarkus/brew,Homebrew/brew,mahori/brew,konqui/brew,rwhogg/brew,vitorgalvao/brew,sjackman/homebrew,bfontaine/brew,pseudocody/brew,vitorgalvao/brew,mgrimes/brew,maxim-belkin/brew,reelsense/brew,alyssais/brew,sjackman/homebrew,JCount/brew,aw1621107/brew,Linuxbrew/brew,nandub/brew,JCount/brew,gregory-nisbet/brew,ilovezfs/brew,amar-laksh/brew_sudo,JCount/brew,pseudocody/brew,pseudocody/brew,amar-laksh/brew_sudo,alyssais/brew,jmsundar/brew,sjackman/homebrew,alyssais/brew,staticfloat/brew,staticfloat/brew,bfontaine/brew,mahori/brew,hanxue/linuxbrew,bfontaine/brew,gregory-nisbet/brew,tonyg/homebrew,tonyg/homebrew,claui/brew,gordonmcshane/homebrew,Linuxbrew/brew,tonyg/homebrew,aw1621107/brew,mahori/brew,jmsundar/brew,maxim-belkin/brew,hanxue/linuxbrew,gregory-nisbet/brew,Homebrew/brew,maxim-belkin/brew,reelsense/brew,mistydemeo/homebrew,zmwangx/brew,gordonmcshane/homebrew,reitermarkus/brew,DomT4/brew,aw1621107/brew,zmwangx/brew,konqui/brew,AnastasiaSulyagina/brew,toonetown/homebrew,rwhogg/brew,EricFromCanada/brew,gordonmcshane/homebrew