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 $0
user@workstation:~/dgraph$ echo $0 bash
Creating a completion script for Bash shell
-
To generate a
dgraph-completion.sh
configuration file for your<SHELL>
, run thecompletion
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.
-
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
sudo
previleges to run it:chmod +x ~/dgraph-completion.sh
-
Open the
.bashrc
file with any text editor. You might needsudo
previliges to apply changes. For example:nano ~/.bashrc
-
Add the path to
dgraph-completion.sh
using the following syntax and save the file:. path/to/dgraph-completion.sh
-
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