如何在OpenBSD上使用git设置自动完成?

3
我想在ksh和openBSD 5.8/5.9上设置git命令的自动完成。以前它已经安装了,但突然间就消失了,所以我必须打字或复制粘贴大量的文本。
它应该像在OSX或Ubuntu中一样工作,你输入git merge X...并按下“tab”键,它就会在终端中完成分支名称的其余部分。
3个回答

3
您需要一个脚本来完成这个任务。Unix/git-bash已经有了这个脚本。
在此处阅读相关内容:https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks#Auto-Completion 您可以选择多种安装方式,只需选择适合您的方式即可。
在此处查看更多信息:https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion

OpenBSD脚本

以下是您可以使用的OpenBSD脚本链接。 该文件具有包含所有说明的标题。
在此处查看更多信息:http://www.ualberta.ca/dept/aict/uts/software/openbsd/ports/4.6/i386/obj/git-1.7.0/git-1.7.0/contrib/completion/git-completion.bash

上述脚本说明:

#!bash
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
#    *) local and remote branch names
#    *) local and remote tag names
#    *) .git/remotes file names
#    *) git 'subcommands'
#    *) tree paths within 'ref:path/to/file' expressions
#    *) common --long-options
#
# To use these routines:
#
#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
#    2) Added the following line to your .bashrc:
#        source ~/.git-completion.sh
#
#    3) Consider changing your PS1 to also show the current branch:
#        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
#
#       The argument to __git_ps1 will be displayed only if you
#       are currently in a git repository.  The %s token will be
#       the name of the current branch.
#
#       In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
#       value, unstaged (*) and staged (+) changes will be shown next
#       to the branch name.  You can configure this per-repository
#       with the bash.showDirtyState variable, which defaults to true
#       once GIT_PS1_SHOWDIRTYSTATE is enabled.
#
#       You can also see if currently something is stashed, by setting
#       GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
#       then a '$' will be shown next to the branch name.
#
#       If you would like to see if there're untracked files, then you can
#       set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
#       untracked files, then a '%' will be shown next to the branch name.

这个是针对bash的。我猜ksh没有类似的东西? - ftshtw
不知道,我是一个 bash/sh/zsh 用户。从未使用过 ksh。 - CodeWizard
它不适用于ksh,但你的脚本适用于bash。我会等待找到一个ksh的替代方案,如果没有,我将转向bash。 - ftshtw
很高兴能够帮助您。如果我的回答对您有所帮助,请不吝赐予认可并投票支持,感激不尽。 - CodeWizard

0

0

据我所知,ksh 没有 git 自动补全脚本。你可以将硬编码的补全条目添加到 git 命令中。不幸的是,这会阻止文件自动补全。

# Add auto-completion entries to git
set -A complete_git status commit clone rebase bisect --patch --interactive

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接