brew doctorで*-configが複数のディレクトリにあるときの警告の対処法

brew doctorしたとき、PATHが通ってる*-configがあると./configureスクリプトが自分の設定ファイルと勘違いする可能性があるという警告。

*-configがひとつのディレクトリだけにあるときの対処はウェブ上に多くあるのですが、以下のように、*-configが複数のディレクトリにあるときの対処法を書いておきます。

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
    /Users/haruka/.phpenv/shims/php-config
    /Users/haruka/.pyenv/shims/python-config
    /Users/haruka/.pyenv/shims/python3-config
    /Users/haruka/.pyenv/shims/python3.4-config
    /Users/haruka/.pyenv/shims/python3.4m-config

パターンマッチで置換をするのですが、

${name/pattern/repl}

これで、nameのpatternにマッチする部分をreplで置換します。replが空の場合はマッチした部分は削除します。

envコマンドも用いて、以下を.zshrcに書いてbrewを実行するときだけ該当パスを外すようにできます。

alias brew="env PATH=${PATH/\/Users\/haruka\/\.phpenv\/shims:/} brew"

ここまでは割とウェブ上にあります。

本題です。

*-configが複数のディレクトリにあるときは、先程のパターンマッチのnameのところを入れ子にして対処します。

alias brew="env PATH=${${PATH/\/Users\/haruka\/\.phpenv\/shims:/}/\/Users\/haruka\/\.pyenv\/shims:/} brew"

案外単純なのですが、この方法に行き着くまでに結構時間かかりました。もっと綺麗な方法がありましたら教えていただきたいです。

参考
phpenv入れてる時brew doctorしたら出るWarning消した – Qiita
シェルスクリプトの変数展開(評価)でパターンマッチ : おまえのログ

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です