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

  • Install Dgraph.
  • Determine the shell you are running:
    echo $0
    An output similar to the following appears:
    user@workstation:~/dgraph$ echo $0

Creating a completion script for Bash shell

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

    dgraph completion <SHELL> > ~/

    The contents of the file is similar to:

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

    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' ~/
  3. Make the file executable by running the following command. You may require root user sudo privileges to run it:

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

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

    . path/to/
  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:

user@workstation:~/dgraph$ dgraph 
acl            cert           debug          increment      migrate        tool           zero
alpha          completion     debuginfo      live           raftmigrate    upgrade        
bulk           conv           export_backup  lsbackup       restore        version