セカンドユーザーの zcompinit
Mac + Homebrew をマルチユーザーで使ってて、 セカンドユーザーでターミナル立ち上げたら zcompinit が insecure だ何だって警告してくるのがすごくイヤでちょっと調べてみた
警告が出る理由
- brew がインストールしたファイルの owner は root ではなく brew したユーザー
- つまり、brew でインストールされた補完関数の owner も root ではなく別ユーザー
- compinit のセキュアチェックは root か自分自身以外が編集できる状態だと警告を出す
解決方法
解決方法は2つ
- compinit がロードする補完関数の owner を root に変更する
- セキュアチェックを無視(-u)、またはセキュアでないものはいれない(-i)
brew 管理下にあるファイルの owner を変更したら、今度は brew がごちゃごちゃしてくるので後者を選択
zplug で compinit されていたので $ZPLUG_HOME/repos/zplug/zplug/base/core/load.zsh を修正して compinit に -u オプションを追加
... # Plugins with defer-level set source "$_zplug_cache[defer_1_plugin]" compinit -u -d "$ZPLUG_HOME/zcompdump" if (( $_zplug_boolean_true[(I)$is_verbose] )); then __zplug::io::print::f \ --zplug "$fg[yellow]Run compinit$reset_color\n" fi source "$_zplug_cache[defer_2_plugin]" source "$_zplug_cache[defer_3_plugin]" ...
ちとめんどう
補足
compinit のオプションに関しては以下を参考
# The -C flag bypasses both the check for rebuilding the dump file and the
# usual call to compaudit; the -i flag causes insecure directories found by
# compaudit to be ignored, and the -u flag causes all directories found by
# compaudit to be used (without security checking). Otherwise the user is
# queried for whether to use or ignore the insecure directories (which
# means compinit should not be called from non-interactive shells).
(引用) https://github.com/zsh-users/zsh/blob/master/Completion/compinit