概要
M1 Macbook Airを買ったので、環境構築している際に発生した話。
zsh-completionsはzshの補完を強化してくれる機能だが、インストール時にちょっとつまづいたのでメモ。
brewからインストール
brew install zsh-completions
するとこんな表示が出ます。
To activate these completions, add the following to your .zshrc:
#
# Executes commands at the start of an interactive session.
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
You may also need to force rebuild `zcompdump`:
rm -f ~/.zcompdump; compinit
Additionally, if you receive "zsh compinit: insecure directories" warnings when attempting
to load these completions, you may need to run this:
chmod -R go-w '/opt/homebrew/share/zsh'
指示に従って操作
1. ~/.zshrcに表示されたスクリプトをコピペ
vimなど適当なエディタを開いて、以下を~/.zshrc
に貼り付け
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
2. 表示されたコマンドを実行
❯ rm -f ~/.zcompdump; compinit
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]? y
ディレクトリが安全じゃないと怒られますが、yを押します。
3. 上記のエラーを消す
"zsh compinit: insecure directories"
が表示されたら、chmod -R go-w '/opt/homebrew/share/zsh'
を実行してねとあるので、実行します。
❯ chmod -R go-w '/opt/homebrew/share/zsh'
4. .zshrcをリロードしてチェック
1.の手順で書き込んだ.zshrcの内容を読み込みます
❯ source ~/.zshrc
すると以下のメッセージが
zsh compinit: insecure directories, run compaudit for list.
手順通りにやったのに消えてない!!
原因:chmodで権限変更するディレクトリが違った
zsh compinit: insecure directories, run compaudit for list.
このメッセージを見る限り、compauditで安全でないディレクトリが見られるようです。
❯ compaudit
There are insecure directories:
/opt/homebrew/share
先ほどchmod
で権限変更したパスは/opt/homebrew/share/zsh
だったので、これが原因のようです。
3.で叩いたコマンドを以下に変更して実行します。
chmod -R go-w '/opt/homebrew/share'
すると、
❯ source ~/.zshrc
(なにも表示されない)
無事、警告が消えてくれました。
各種バージョンによって権限変更するディレクトリが異なるっぽいので注意ですね。
環境
- Macbook Air (M1,2020, 16GB RAM)
- zsh 5.8 (x86_64-apple-darwin21.0)
- zsh-completions 0.33.0_1