Skip to content

Conversation

tbhaxor
Copy link
Contributor

@tbhaxor tbhaxor commented Mar 15, 2022

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

  • 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:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • 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.

Copy link
Member

@NoahGorny NoahGorny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done @tbhaxor !

@tbhaxor
Copy link
Contributor Author

tbhaxor commented Feb 23, 2023

@NoahGorny @davidpfarrell ping :)

@davidpfarrell
Copy link
Contributor

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?

@seefood seefood merged commit da2f035 into Bash-it:master Nov 6, 2024
@tbhaxor tbhaxor deleted the improve/export-completion branch November 6, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants