dbash: docker bash alias with autocompletion

revision 13a9b535a022adf0ef708e0f99a02b2dcc32c7e5

raw

setup-debian13.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# docker bash command with autocompletion
# standard docker completion provided by docker-ce-cli
 
# enable debugging with this variable:
#export BASH_COMP_DEBUG_FILE=/dev/stdout
 
source /usr/share/bash-completion/completions/docker
function dbash() {
    docker exec -it "$1" bash;
}
function dbashwww() {
    docker exec -it "$1" su -s/bin/bash  www-data;
}
function dtail() {
    docker logs -f "$@";
}
_dbash() {
    #__start_docker loads variables itself and can't be used
    local cur prev words cword split
    cur="$2"
    words=(docker stop "$2")
    cword=2
 
    local out directive
    __docker_get_completion_results
    __docker_process_completion_results
}
complete -F _dbash dbash
complete -F _dbash dbashwww
complete -F _dbash dtail
 
raw

setup-ubuntu-20.04.sh

1
2
3
4
5
6
7
8
function dbash() { docker exec -it "$1" bash; }
_dbash() { cur="${COMP_WORDS[COMP_CWORD]}"; __docker_complete_containers_running; }
complete -F _dbash dbash
 
# automatically login as www-data user
function dbashwww() { docker exec -it "$1" su -s /bin/bash www-data; }
complete -F _dbash dbashwww
 

History