简体   繁体   English

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

[英]How to setup auto-completion with git on openBSD?

I want to setup auto-completion for git commands in ksh and openBSD 5.8/5.9.我想在 ksh 和 openBSD 5.8/5.9 中为 git 命令设置自动完成。
Somehow it was installed previously and suddenly disappeared so I have to type or copy and paste large amounts of text.不知何故,它以前安装过,突然消失了,所以我必须键入或复制并粘贴大量文本。

It should work as in OSX or Ubuntu, where you type git merge X... and press the "tab" key so it completes the rest of the branch name in terminal.它应该像在 OSX 或 Ubuntu 中一样工作,在其中键入git merge X...并按“tab”键,以便它在终端中完成分支名称的其余部分。

You will need to have a script for that.您将需要为此编写脚本。 Unix/git-bash are already have this script. Unix/git-bash 已经有了这个脚本。

Read about it here: 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 : //git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks https://git-scm.com/book/en/v1/Git-Basics-提示和技巧#自动完成

You have many options on how to install it.关于如何安装它,您有很多选择。 Simply choose the right way for you.,只需为您选择正确的方式。,

https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion


OpenBSD Script OpenBSD 脚本

Here is a link to the OpenBSD script which you can use.这是您可以使用的 OpenBSD 脚本的链接。
The file has header with all the instructions how to do it.该文件的标题包含如何执行此操作的所有说明。

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 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


The above script instructions:以上脚本说明:

#!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.

Download the bash completion file here: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash在此处下载 bash 完成文件: https : //raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

I put it in: /usr/local/share/bash-completion/completions/git我把它放在:/usr/local/share/bash-completion/completions/git

Then make sure your shell is set to bash and then source that file.然后确保您的 shell 设置为 bash,然后获取该文件。 My bashrc section looks like this: https://gist.github.com/ckuttruff/db8349e0cc3a1930dc4f5f17a042e1f6我的 bashrc 部分如下所示: https : //gist.github.com/ckuttruff/db8349e0cc3a1930dc4f5f17a042e1f6

Afaik there is no git auto-completion script for ksh. Afaik 没有用于 ksh 的 git 自动完成脚本。 What you can do is add hard coded completion entries to the git command.您可以做的是将硬编码的完成条目添加到 git 命令。 Unfortunately this prevents file auto-completion.不幸的是,这会阻止文件自动完成。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM