首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何让git别名的bash完成工作?

如何让git别名的bash完成工作?
EN

Stack Overflow用户
提问于 2018-06-05 01:50:36
回答 1查看 0关注 0票数 0

我创建了git别名~/.gitconfig

代码语言:javascript
复制
[alias]
xxx = !bash -c 'git rebase ...'

有没有办法让bash自动完成git xxx像通常的别名一样:

代码语言:javascript
复制
__git_complete grb _git_rebase
EN

回答 1

Stack Overflow用户

发布于 2018-06-05 11:45:34

〜/ .bashrc:

代码语言:javascript
复制
_git_xxx ()
{
  _git_rebase
}

〜/.gitconfig

代码语言:javascript
复制
[alias]
xxx = !bash -c 'git rebase ...'

_git_rebase看起来像这样:

代码语言:javascript
复制
_git_rebae ()
{
        __git_find_repo_path
        if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
                __gitcomp "--continue --skip --abort --quit --edit-todo"
                return
        elif [ -d "$__git_repo_path"/rebase-apply ] || \
            [ -d "$__git_repo_path"/rebase-merge ]; then
                __gitcomp "--continue --skip --abort --quit"
                return
        fi
        __git_complete_strategy && return
        case "$cur" in
        --whitespace=*)
                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
                return
                ;;
        --*)
                __gitcomp "
                        --onto --merge --strategy --interactive
                        --preserve-merges --stat --no-stat
                        --committer-date-is-author-date --ignore-date
                        --ignore-whitespace --whitespace=
                        --autosquash --no-autosquash
                        --fork-point --no-fork-point
                        --autostash --no-autostash
                        --verify --no-verify
                        --keep-empty --root --force-rebase --no-ff
                        --exec
                        "

                return
        esac
        __git_complete_refs
}

为了防止代码重复,你可以将你的别名完成绑定到现有的代码:

代码语言:javascript
复制
_git_xxx ()
{
  _git_rebase
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100008628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档