繁体   English   中英

如何在Windows 10 bash中使用别名来完成bash完成?

[英]How do I get bash completion to work with aliases in Windows 10 bash?

我有一个修改过的aliases.sh文件

alias gc='git checkout'

在签出长分支名称时,如果我输入gc <branchstring> + TAB,则自动完成不起作用,以便显示完整的分支名称。

我查看了这个帖子中的所有内容,试图让它适用于&定制kpsfoo所说的内容,但适用于Windows 10操作系统。

步骤是:

1)从中复制git-completion.bash文件

<your git install folder>/etc/git-completion.bash

C:\\Users\\<YourUserName>\\git-completion.bash

2)添加以下代码行:

source ~/git-completion.bash到你的aliases.sh文件

(可以在<your git install folder>\\etc\\profile.d

3)在aliases.sh文件中的source ~/git-completion.bash行之后的任何地方添加alias gc='git checkout'并添加__git_complete gco _git_checkout

4)重新启动你的git bash并享受你的别名自动完成!

示例:如果我有一个分支VeryVeryLongBranchName并且我当前在dev分支上,并且想要切换到它,而不是键入git checkout VeryVeryLongBranchName我只能键入gc Very + TAB键 ,它相当于上面的指令。

我在aliases.sh文件中拥有的所有内容的一个示例(并且它将被扩展,因为我发现需要其他别名)将是:

alias ga="git add"
alias gb='git branch'
alias gba="git branch -a"
alias gc='git checkout'
alias gcb='git checkout -b'
alias gcam='git commit -a -m'
alias gm='git merge --no-ff'
alias gps='git push wpdev dev'
alias gpsm='git push wpdev master'
alias gpl='git pull wpdev dev'
alias gplm='git pull wpdev master'
alias st='git status'
alias l='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'
alias last='log -1 HEAD'
alias gs='git stash'

# Enable the __git_complete function to autocomplete aliases once you press TAB
source ~/git-completion.bash

__git_complete ga _git_add
__git_complete gc _git_checkout
__git_complete gm _git_merge
__git_complete gb _git_branch
__git_complete gba _git_branch
__git_complete l _git_log

case "$TERM" in
xterm*)
    # The following programs are known to require a Win32 Console
    # for interactive usage, therefore let's launch them through winpty
    # when run inside `mintty`.
    for name in node ipython php php5 psql python2.7
    do
        case "$(type -p "$name".exe 2>/dev/null)" in
        ''|/usr/bin/*) continue;;
        esac
        alias $name="winpty $name.exe"
    done
    ;;
esac

值得注意的是: alias gm='git merge --no-ff'__git_complete gm _git_merge (当你输入gm加上你的分​​支名称中的一个字符串并按下TAB时 ,它会自动完成,并且在你运行命令之后,合并将考虑--no-ff规则)

暂无
暂无

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

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