首先是要ssh-agend
按需添加SSH密钥,但是由于OpenSSH无法实现,因此我想出了这个zsh脚本。但是由于某种原因,我无法弄清楚,它不是只在“ before”ssh
或“ before”之前运行,而是git
在任何命令之前运行,甚至是空命令。
git ssh () {
# Does the agent handle any keys?
ssh-add -l &>/dev/null
# True if last executed command (ssh-add -l) exits non-zero.
if [ $? -ne 0 ]; then
ssh-add
fi
# Execute git or ssh with all parameters, and not this function
command $0 "$@"
}
为什么在每条命令之后执行此功能,而不是仅在输入git
或时执行ssh
?
我尝试使用该函数zsh -f
(在发布之前应该完成此操作。),发现它按预期工作。造成此问题的其他原因,因此我将在可能时关闭此问题。
编辑:
对于那些对问题是什么以及如何解决有兴趣的人,请看下面。
我使用了zsh框架ZIM,该框架vcs_info
用于检查git是否使用了当前目录。这需要调用git。vcs_info
它本身并不直接调用git,这似乎不是默认情况。
但是,感谢Freenode上#zsh上的ft,
zstyle ':vcs_info:git:*:-all-' command =git
以~/.zshrc
框架已经采购后,已经修复了这个问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句