现象
为了进入到Application文件夹,输入App后按tab键,想使用zsh的快捷提示功能,结果报错。如图所示:
排查
1.重新打开iTerm窗口
刚打开命令行时,有一堆提示没有细看,现在重新打开命令行查看提示。
[oh-my-zsh] For safety, we will not load completions from these directories until
[oh-my-zsh] you fix their permissions and ownership and restart zsh.
[oh-my-zsh] See the above list for directories with group or other writability.
[oh-my-zsh] To fix your permissions you can do so by disabling
[oh-my-zsh] the write permission of "group" and "others" and making sure that the
[oh-my-zsh] owner of these directories is either root or your current user.
[oh-my-zsh] The following command may help:
[oh-my-zsh] compaudit | xargs chmod g-w,o-w
[oh-my-zsh] If the above didn't help or you want to skip the verification of
[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to
[oh-my-zsh] "true" before oh-my-zsh is sourced in your zshrc file.
┌────────────────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) /Users/jsk/.config │
└────────────────────────────────────────────────────────┘
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?
按提示执行:
sudo chown -R $USER:$(id -gn $USER) /Users/jsk/.config
注意哈,每个人提示的可能不一样。
2.继续重新打开iTerm窗口
窗口提示信息如下:
[oh-my-zsh] Insecure completion-dependent directories detected:
drwxrwxr-x 3 jsk admin 96 4 22 2020 /usr/local/share/zsh
drwxrwxr-x 6 jsk admin 192 4 22 2020 /usr/local/share/zsh/site-functions
[oh-my-zsh] For safety, we will not load completions from these directories until
[oh-my-zsh] you fix their permissions and ownership and restart zsh.
[oh-my-zsh] See the above list for directories with group or other writability.
[oh-my-zsh] To fix your permissions you can do so by disabling
[oh-my-zsh] the write permission of "group" and "others" and making sure that the
[oh-my-zsh] owner of these directories is either root or your current user.
大致意思是:需要确保上面目录的所有者要么是root用户,要么是您当前的用户。
[oh-my-zsh] The following command may help:
[oh-my-zsh] compaudit | xargs chmod g-w,o-w
[oh-my-zsh] If the above didn't help or you want to skip the verification of
[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to
[oh-my-zsh] "true" before oh-my-zsh is sourced in your zshrc file.
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?
compinit: initialization aborted
complete:13: command not found: compdef
从第一行提示可以看出:检测到不安全的完整依赖目录,/usr/local/share/zsh
和/usr/local/share/zsh/site-functions
。这些目录的所有者要么是root用户,要么是当前的用户。
那就给当前用户重新授权下:
chmod 755 /usr/local/share/zsh
chmod 755 /usr/local/share/zsh/site-functions
chmod是“change mode”的意思,用于改变Linux文件代表不同用户对此文件权限的一串flag。
chmod 755 的含义是所有用户都拥有此文件的读权限和执行权限,只有Owner拥有此文件的写权限。因此我们也可以说chmod 755 的作用等同于 chmod u=rwx,go=rx (其中u代表user,g代表group, o代表others)
3.继续重新打开iTerm窗口
command+N重新打开一个窗口,可以看到没有错误信息提示了,按Tab键也有目录提示了。