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:
An output similar to the following appears:
echo $0user@workstation:~/dgraph$ echo $0
bash
Creating a completion script for Bash shell
-
To generate a
dgraph-completion.shconfiguration file for your<SHELL>, run thecompletioncommand:dgraph completion <SHELL> > ~/dgraph-completion.shThe 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.
-
You can comment out the 2 lines with a
#, or remove them with the following command:sed -i.bak '1d;2d' ~/dgraph-completion.sh -
Make the file executable by running the following command. You may require root user
sudoprivileges to run it:chmod +x ~/dgraph-completion.sh -
Open the
.bashrcfile with any text editor. You might needsudoprivileges to apply changes. For example:nano ~/.bashrc -
Add the path to
dgraph-completion.shusing the following syntax and save the file:. path/to/dgraph-completion.sh -
Reload the
bashrcsettings 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