ZSH 完成功能损坏

ZSH 完成功能损坏

我安装了 oh-my-zsh,已经运行了将近一年,现在突然坏了。当我打开终端时,我得到:

/home/marcel/.oh-my-zsh/lib/theme-and-appearance.zsh:2: colors: function definition file not found
/home/marcel/.oh-my-zsh/oh-my-zsh.sh:78: compinit: function definition file not found
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:80: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:93: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:100: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:109: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:119: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:129: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:138: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:144: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:147: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:150: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:153: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:163: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:166: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:168: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:182: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:193: command not found: compdef
$SPACESHIP_PROMPT_TRUNC is deprecated. Use $SPACESHIP_DIR_TRUNC instead.
spaceship_setup:3: add-zsh-hook: function definition file not found
spaceship_setup:4: add-zsh-hook: function definition file not found
$SPACESHIP_PROMPT_TRUNC is deprecated. Use $SPACESHIP_DIR_TRUNC instead.
spaceship_setup:3: add-zsh-hook: function definition file not found
spaceship_setup:4: add-zsh-hook: function definition file not found

我环顾四周,发现很多其他答案都建议运行compaudit。运行这个答案会给我带来zsh: compaudit: function definition file not found

我已尝试过:

  1. rm ~/.zcompdump*
  2. 重新安装 oh-my-zsh
  3. 从源代码重新安装 zsh
  4. 添加/usr/share/zsh/functions$fpath
  5. chown -R 755 /usr/share/zsh/functions
  6. 加载并compaudit运行zsh -f

我的环境:

  • uname -aLinux Hermes 4.11.6-1-ARCH #1 SMP PREEMPT Sat Jun 17 08:19:42 CEST 2017 x86_64 GNU/Linux
  • zsh --versionzsh 5.3.1 (x86_64-unknown-linux-gnu)
  • which zsh/usr/local/bin/zsh

编辑:

我已经确认这是权限问题。如果我

sudo zsh -f
autoload -U compaudit
compaudit

该命令按预期工作。然后我做了

sudo chmod 777 /usr/share/zsh/ -R # Just for testing I promise

zsh: compaudit: function definition file not found跑步的时候仍然能做到compaudit

我也试过

sudo chown user:users /usr/share/zsh/ -R

但仍然无法正常工作。如果所有这些文件都归我的用户所有并且都是 777,那么 zsh 如何以 root 身份而不是以我的用户身份工作?

答案1

根据线索颜色、compinit 和 git 插件的安装问题 #4757,似乎验证了“$FPATH 变量内容“包含您安装该功能的正确路径应该有助于解决问题。

此外,将 zsh 内容复制到根目录或已定义的路径$FPath也可能有助于解决此问题。

首先要验证您的 FPATH 变量内容:echo $FPATH。在正常情况下,返回类似以下内容: /home/charmander/.oh-my-zsh/plugins/git:/home/charmander/.oh-my-zsh/functions:/home/charmander/.oh-my-zsh/completions:/home/charmander/.oh-my-zsh/plugins/python:/home/charmander/.oh-my-zsh/plugins/pip:/home/charmander/.oh-my-zsh/plugins/git:/home/charmander/.oh-my-zsh/functions:/home/charmander/.oh-my-zsh/completions:/usr/share/zsh/site-functions:/usr/share/zsh/5.0.2/functions

在我的情况下它返回: /opt/intel/composer_xe_2011_sp1.7.256/mkl/include。当我尝试删除 .oh-my-zsh 并仅运行 zsh 时返回此: /usr/share/zsh/5.0.2/scripts/newuser:6: zsh-newuser-install: function definition file not found。在网络上搜索我发现了这个错误报告: zsh:缺少许多函数定义 zsh-newuser-install、compinit 等这表明英特尔编译器可能会对变量进行覆盖:/

因此,如果您无法运行此命令 chsh -s $(which zsh),解决此问题的一种方法是将以下几行插入到您的 .bash_profile 中。

FPATH=/home/modelagem/beatriz.fonseca/.oh-my-zsh/plugins/python:/home/modelagem/beatriz.fonseca/.oh-my-zsh/plugins/pip:/home/modelagem/beatriz.fonseca/.oh-my-zsh/plugins/git:/home/modelagem/beatriz.fonseca/.oh-my-zsh/functions:/home/modelagem/beatriz.fonseca/.oh-my-zsh/completions:/usr/share/zsh/site-functions:/usr/share/zsh/5.0.2/functions

export FPATH

来源

此外,根据颜色:未找到函数定义文件 #4607,看来其他人已经通过添加$HOME/usr/share/zsh/'version of zsh'/functions来解决这个问题,因为安装 zsh 可能$HOME/usr会导致这个问题。


进一步阅读

   FPATH  The search path for function definitions.  The directories in this  path  are  searched
                 for  a  file  with the same name as the function or command when a function with the -u
                 attribute is referenced and when a command is not found.  If an  executable  file  with
                 the name of that command is found, then it is read and executed in the current environ-ment. environment.
                 ment.  Unlike PATH, the current directory must be represented explicitly by  .   rather
                 than by adjacent : characters or a beginning or ending :.

来源


9.1 自动加载函数

可以使用内置的 autoload(或“functions -u”或“typeset -fu”)将函数标记为未定义。这样的函数没有主体。首次执行该函数时,shell 会使用 fpath 变量的元素来搜索其定义。

来源

答案2

我只想补充一点,如果您安装了两个不同版本的 ZSH,也可能会发生此错误。确保您的 FPATH 中没有任何与您用于实际登录 shell 的 ZSH 版本不兼容的内容。

答案3

我找到了一个线索,或者至少是另一个失败的例子。这也将“部分”责任归咎于 zsh。确保您确实追踪到错误发生的位置。我正在从 bash 转移到 zsh,并尝试在我的 .rc 文件中保留尽可能多的常见内容。现在失败的一件事是这样的分配(BASH 习语):

: ${*var*:=DEF_VAR_VAL}
zsh: :: function definition file not found
# `:=' may also be one of =, :=, etc.
# Oddly, the operator works anyway and *var* is set if needed.
# However, the following works w/nary a problem:
var=${var-DEV_VAR_VAL}
# as does:
true ${var:=DEF_VAR_VAL}
# Odd, because `:' is supposed to be an alias for true(1)

医生仍然说:应该有效,而且以前也有效。

:[ arg ... ] 此命令不执行任何操作,尽管正常论证扩展执行此操作可能会对 shell 参数产生影响。返回零退出状态。

来源:http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html

注意:我没看到斜体也不大胆的在我的预览中,所以它们可能不会出现。

相关内容