我想在ksh和openBSD 5.8 / 5.9中为git命令设置自动完成。
不知何故它以前安装过并突然消失,所以我必须输入或复制并粘贴大量文本。
它应该像OSX或Ubuntu一样工作,您可以在其中键入git merge X...
并按下"标签"键,以便完成终端中其余的分支名称。
答案 0 :(得分: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脚本的链接 该文件包含标题,其中包含所有说明。
#!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.
答案 1 :(得分:0)
在此处下载bash完成文件: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
我把它放在: / usr / local / share / bash-completion / completions / git
然后确保您的外壳设置为bash,然后获取该文件。我的bashrc部分如下所示: https://gist.github.com/ckuttruff/db8349e0cc3a1930dc4f5f17a042e1f6
答案 2 :(得分:0)
Afaik没有ksh的git自动完成脚本。您可以做的是将硬编码的完成条目添加到git命令。不幸的是,这阻止了文件自动完成。
# Add auto-completion entries to git
set -A complete_git status commit clone rebase bisect --patch --interactive