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

bash-completion: add completion script #261

Merged
merged 1 commit into from Nov 30, 2020
Merged

bash-completion: add completion script #261

merged 1 commit into from Nov 30, 2020

Conversation

audeoudh
Copy link
Contributor

Confer #260.

Copy link
Collaborator

@ebiggers ebiggers left a comment

Choose a reason for hiding this comment

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

Thanks, a few comments. It's hard to review this without experience writing bash completion scripts, though.

util/fscrypt_completion Outdated Show resolved Hide resolved
util/fscrypt_completion Outdated Show resolved Hide resolved
util/fscrypt_completion Outdated Show resolved Hide resolved
util/fscrypt_completion Outdated Show resolved Hide resolved
util/fscrypt_completion Outdated Show resolved Hide resolved
util/fscrypt_completion Outdated Show resolved Hide resolved
util/fscrypt_completion Outdated Show resolved Hide resolved
util/fscrypt_completion Outdated Show resolved Hide resolved
@ebiggers
Copy link
Collaborator

I think I'm finally understanding most of this, but it's difficult to read because of the code duplication with the bash-completion boilerplate. Could you add some helper functions like:

_fscrypt_complete_mountpoint()                                                   
{                                                                                
    COMPREPLY=($(compgen -W "$(_fscrypt_mountpoints)" -- "$cur"))                
}

_fscrypt_complete_word()                                                         
{                                                                                
    local wordlist=$1                                                            
                                                                                 
    COMPREPLY=($(compgen -W "$wordlist" -- "$cur"))                              
}                                                                                
                                                                                 
_fscrypt_complete_option()                                                       
{                                                                                
    local additional_opts=${1-}                                                  
    local GLOBAL_OPTS="--verbose --quiet --help"                                 
                                                                                 
    _fscrypt_complete_word "$additional_opts $GLOBAL_OPTS"                       
}                                                                                

... and use them everywhere where they can. Also, please use if instead of case when there are only two branches.

That should make things a lot easier to understand.

E.g. the following:

        case $cur in
            -*)
                COMPREPLY=($(compgen -W "--time= --force ${GLOBAL_OPTS}" \
                           -- "${cur}"))
                ;;
            *)
                COMPREPLY=($(compgen -W "$(_fscrypt_mountpoints)" -- "${cur}"))
                ;;
        esac

... would become:

        if [[ $cur == -* ]]; then
            _fscrypt_complete_option "--time= --force"
        else
            _fscrypt_complete_mountpoint
        fi

@ebiggers
Copy link
Collaborator

Also, please squash your commits into one. Thanks!

@audeoudh
Copy link
Contributor Author

I mainly:

  • changed “too simple” case structures to if/else blocks,
  • added functions for conceptualize bash-completion typical code,
  • added more comments in the script,
  • added the script in make lint and make install.
  • squashed commits

Let me know if there is still something to do.

@ebiggers
Copy link
Collaborator

It looks much better now, thanks. Can you address the two comments I just left (remove --drop-caches, and update make uninstall)? Afterwards I think this will be ready to merge, unless @josephlr has comments.

@ebiggers ebiggers merged commit b74cd30 into google:master Nov 30, 2020
@ebiggers
Copy link
Collaborator

Thanks, merged now.

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.

None yet

2 participants