Skip to content

Commit a23c541

Browse files
committed
Merge branch 'cli-autocompletion' into 'master'
feat: enable bash autocompletion for Database Lab CLI See merge request postgres-ai/database-lab!237
2 parents dd4db47 + 4e75fa8 commit a23c541

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Install Database Lab client CLI on your Linux machine (e.g., Ubuntu):
2929
curl https://gitlab.com/postgres-ai/database-lab/-/raw/master/scripts/cli_install.sh | bash
3030
```
3131

32+
### Activate CLI autocompletion:
33+
```bash
34+
sudo curl https://gitlab.com/postgres-ai/database-lab/-/raw/master/scripts/bash_autocomplete --output /etc/bash_completion.d/dblab
35+
source /etc/bash_completion.d/dblab
36+
```
3237

3338
### How to use CLI
3439
- [How to install and initialize Database Lab CLI](https://postgres.ai/docs/guides/cli/cli-install-init)

cmd/cli/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func main() {
7676
EnvVars: []string{"DBLAB_CLI_DEBUG"},
7777
},
7878
},
79+
EnableBashCompletion: true,
7980
}
8081

8182
adoptTemplates()

scripts/bash_autocomplete

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /bin/bash
2+
3+
: ${PROG:=$(basename ${BASH_SOURCE})}
4+
5+
6+
7+
_cli_bash_autocomplete() {
8+
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
9+
local cur opts base
10+
COMPREPLY=()
11+
cur="${COMP_WORDS[COMP_CWORD]}"
12+
if [[ "$cur" == "-"* ]]; then
13+
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
14+
else
15+
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
16+
fi
17+
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
18+
return 0
19+
fi
20+
}
21+
22+
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
23+
unset PROG

0 commit comments

Comments
 (0)