Ask a Question

Create a completion script

Create a completion script The completion script is code that uses the builtin bash command complete to define which completion suggestions can be displayed for a given executable. The nature of the completion options vary from simple static to highly sophisticated.

Before you begin

Creating a completion script for Bash shell

  1. To generate a dgraph-completion.sh configuration file for your <SHELL>, run the completion command:

    dgraph completion <SHELL> > ~/dgraph-completion.sh
    

    The contents of the file is similar to:

    [Decoder]: Using assembly version of decoder
    Page Size: 4096
    # bash completion for dgraph                               -*- shell-script -*-
    
    __dgraph_debug()
    {
     if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
         echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
     fi
    } 
    ...
    ..
    .
    

    The generated file has 2 lines at the beginning that need to be removed for the script to run properly.

  2. You can comment out the 2 lines with a #, or remove them with the following command:

    sed -i.bak '1d;2d' ~/dgraph-completion.sh
    
  3. Make the file executable by running the following command. You may require root user sudo previleges to run it:

    chmod +x ~/dgraph-completion.sh
    
  4. Open the .bashrc file with any text editor. You might need sudo previliges to apply changes. For example:

    nano ~/.bashrc
    
  5. Add the path to dgraph-completion.sh using the following syntax and save the file:

    . path/to/dgraph-completion.sh
    
  6. Reload the bashrc settings with the following command:

    source ~/.bashrc
    

Now you can start typing dgraph and press tab to get auto-completion and suggestions:

[email protected]station:~/dgraph$ dgraph 
acl            cert           debug          increment      migrate        tool           zero
alpha          completion     debuginfo      live           raftmigrate    upgrade        
bulk           conv           export_backup  lsbackup       restore        version