Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run git-completion.bash #175

Closed
andychu opened this issue Aug 30, 2018 · 5 comments
Closed

Run git-completion.bash #175

andychu opened this issue Aug 30, 2018 · 5 comments

Comments

@andychu
Copy link
Contributor

andychu commented Aug 30, 2018

This is a big ambitious issue. Not sure what is necessary, but help appreciated.

https://github.com/git/git/blob/master/contrib/completion/git-completion.bash

This is 3000+ lines of code that you probably don't want to rewrite in a different completion system!

What do zsh and fish do?

@andychu
Copy link
Contributor Author

andychu commented Aug 30, 2018

NOTE: It doesn't even parse under OSH because it has zsh code in it! bash doesn't parse this statically, so it gives no errors.

for c in ${=1}; do

However, it says that part is obsolete, and git-completion.zsh is the replacement.

andychu pushed a commit that referenced this issue Aug 30, 2018
@andychu
Copy link
Contributor Author

andychu commented Sep 11, 2018

NOTE: osh now parses a line at a time because alias requires this. So the zsh thing is no longer an issue.

However osh -n still retains the capability of static parsing, without alias expansion.

@andychu
Copy link
Contributor Author

andychu commented Sep 14, 2018

The number of flags here is pretty small actually:

~/git/oilshell/oil$ grep -w -E 'compgen|compopt|complete' testdata/completion/git-completion.bash 
        # re-assemble words to complete.
# 1: List of newline-separated matching completion words, complete with
        unset $(compgen -v __gitcomp_builtin_)
# 1: List of newline-separated matching paths, complete with all prefix
        compopt -o filenames +o nospace 2>/dev/null ||
        compgen -f /non-existing-dir/ >/dev/null ||
# Generates completion reply with compgen from newline-separated possible
        compopt -o filenames +o nospace 2>/dev/null ||
        compgen -f /non-existing-dir/ >/dev/null ||
                # this command does not take a ref, do not complete it
                                __gitcomp "$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
        complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
                || complete -o default -o nospace -F $wrapper $1

andychu pushed a commit that referenced this issue Sep 14, 2018
- Added parsing of "actions" for compgen -A function / compgen -f.  This
  is like set -o errexit / set -e.
- Added some spec tests, but they don't test much.  They only test
  command line parsing.

Addresses issue #175.
@andychu
Copy link
Contributor Author

andychu commented Sep 14, 2018

COMP_ variables:

$ grep COMP_ git-completion.bash 
case "$COMP_WORDBREAKS" in
*)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
# word completion separators (COMP_WORDBREAKS) to treat as ordinary
# COMP_WORDBREAKS to exclude those characters.  The intent is to
# It is best not to set COMP_WORDBREAKS directly because the value is
# function gets called, COMP_WORDS has already been populated so local
# changes to COMP_WORDBREAKS have no effect.
        exclude="${1//[^$COMP_WORDBREAKS]}"
        cword_=$COMP_CWORD
                words_=("${COMP_WORDS[@]}")
        for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
                        [ -n "${COMP_WORDS[$i]}" ] &&
                        [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
                        words_[$j]=${words_[j]}${COMP_WORDS[i]}
                        if [ $i = $COMP_CWORD ]; then
                        if (($i < ${#COMP_WORDS[@]} - 1)); then
                words_[$j]=${words_[j]}${COMP_WORDS[i]}
                if [ $i = $COMP_CWORD ]; then
                case "$COMP_WORDBREAKS" in
                case "$COMP_WORDBREAKS" in

andychu pushed a commit that referenced this issue Sep 16, 2018
a[i]=x now works.

- Update the spec test numbers.  Down to 92 failures!
- Add a hard test case with alias and LHS array assignment.  bash and
  mksh both pass.

Addresses issue #175.

Also:

- Notes about the parser architecture.
@andychu andychu changed the title Look into what it takes to run git bash completion Run git-completion.bash Nov 5, 2018
@andychu
Copy link
Contributor Author

andychu commented Feb 4, 2019

This is done, or at least I haven't noticed any bugs running it lately.

We can also run git-prompt.sh

@andychu andychu closed this as completed Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant