Git bash-completion with filename support?

后端 未结 4 1317
独厮守ぢ
独厮守ぢ 2020-12-09 12:28

is there a bash-completion script that supports filename completion? I use mostly mercurial and there I can type:

hg diff test/test_
4条回答
  •  旧时难觅i
    2020-12-09 12:59

    This solves the git diff problem for me, put the following in .bashrc:

    alias gid='git diff'
    __gdiff () {
        local cur prev opts
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
        opts=$(git status --porcelain | grep '^.[^ ?]' | cut -b 4-)
    
        case "${prev}" in
            gid)
                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
                ;;
        esac
    }
    complete -F __gdiff gid
    

    And then do gid instead of git diff . It may be simplified, but seems to work well as a quick fix.

提交回复
热议问题