【问题标题】:adding new zshell command line custom git completions添加新的 zshell 命令行自定义 git 完成
【发布时间】:2011-11-24 16:58:47
【问题描述】:

我通过Homebrew 安装了 git。我通过安装在中的脚本获得命令行补全

/usr/local/etc/bash_completion.d/

不过,我也希望我的自定义 git-* 脚本也能完成。

我如何将它添加到现有的 git 完成中?

【问题讨论】:

  • 例如哪个命令?它应该默认工作。

标签: git tab-completion zsh-completion


【解决方案1】:

我给你举几个例子。

  • 为别名添加补全

如果你有这样的 pull 别名:

alias gp='git push'

然后你可以定义别名使用与git-push 相同的补全。

compdef _git gp=git-push
  • 为新命令添加补全

这是一个更难的。为 zsh 编写补全脚本并非易事,您可以查看 in this project 以获得一些指导。例如,看看completion scriptgit-wtf

  • 重用现有补全,但已修改

如果你有这样的脚本在日志中搜索:

query="$1"
shift
git log -S"$query" "$@"

您想使用git-log 的补全,稍作修改:您想先补全搜索字符串,然后使用git-log 的常用选项。然后你可以使用这个:

_git-search () {
if (( CURRENT == 2 )); then
    _message "search string"
    return
fi

CURRENT=$(( $CURRENT - 1 ))
_git-log
}

_git-search "$@"

编辑:另外,要实际使用新定义的完成文件,您必须将存储它们的目录添加到 fpath

【讨论】:

    猜你喜欢
    • 2023-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    相关资源
    最近更新 更多