bash-it icon indicating copy to clipboard operation
bash-it copied to clipboard

Clean export completions

Open tbhaxor opened this issue 3 years ago • 2 comments

Description

This PR fixes SC2016 in completions/available/export.completion.bash file

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x] My code follows the code style of this project.
  • [ ] If my change requires a change to the documentation, I have updated the documentation accordingly.
  • [x] I have read the CONTRIBUTING document.
  • [x] If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • [ ] I have added tests to cover my changes, and all the new and existing tests pass.

tbhaxor avatar Mar 15 '22 02:03 tbhaxor

@NoahGorny @davidpfarrell ping :)

tbhaxor avatar Feb 23 '23 11:02 tbhaxor

So not sure where its from (likely brew completions), but I have a much better completion defined in my local:

$ complete -p export

complete -F _export export
$ type _export

_export is a function

_export () 
{ 
    local cur prev words cword;
    _init_completion -n = || return;
    local i action=variable remove=false;
    for ((i = 1; i < cword; i++))
    do
        case ${words[i]} in 
            -p)
                return
            ;;
            -*f*)
                action=function
            ;;&
            -*n*)
                remove=true
            ;;
            -*)
                continue
            ;;
        esac;
        break;
    done;
    if [[ $cur == *=* ]]; then
        local ocur=$cur oprev=$prev;
        prev=${cur%%=*} cur=${cur#*=};
        _variables && return;
        cur=$ocur prev=$oprev;
    fi;
    case $cur in 
        *=)
            local pval=$(quote "$(eval printf %s \"\$\{${cur%=}-\}\")");
            if [[ $pval != \'\' ]]; then
                COMPREPLY=("$pval");
            else
                cur=${cur#*=};
                _filedir;
            fi
        ;;
        *=*)
            cur=${cur#*=};
            _filedir
        ;;
        *)
            if [[ $cword -eq 1 && $cur == -* ]]; then
                COMPREPLY=($(compgen -W '-p $(_parse_usage "$1")' -- "$cur"));
                return;
            fi;
            local suffix="";
            if ! $remove; then
                suffix="=";
                compopt -o nospace;
            fi;
            COMPREPLY=($(compgen -A $action -S "$suffix" -- "$cur"))
        ;;
    esac
}
$ export -<TAB><TAB>
-f  -n  -p  

Regarding the PR:

- complete -o nospace -S = -W '$(printenv | awk -F= "{print \$1}")' export
+ complete -o nospace -S = -W "$(printenv | awk -F= "{print \$1}")" export

The outer ' seems vital as we want to evaluate the printenv later and not now

So it appears to me that we are actually breaking the completion here?

davidpfarrell avatar Feb 23 '23 18:02 davidpfarrell