From c71c7f4b4f6fe95982c132c42c990e2d4085bb90 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Sun, 18 Oct 2015 08:16:15 -0700 Subject: [PATCH] bash completion for `docker cp` supports copying both ways Signed-off-by: Harald Albers --- contrib/completion/bash/docker | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index de2d24c533..9f6161282a 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -561,9 +561,18 @@ _docker_cp() { return ;; *) + # combined container and filename completion + _filedir + local files=( ${COMPREPLY[@]} ) + __docker_containers_all COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) - __docker_nospace + local containers=( ${COMPREPLY[@]} ) + + COMPREPLY=( $( compgen -W "${files[*]} ${containers[*]}" -- "$cur" ) ) + if [[ "$COMPREPLY" == *: ]]; then + __docker_nospace + fi return ;; esac @@ -571,7 +580,13 @@ _docker_cp() { (( counter++ )) if [ $cword -eq $counter ]; then - _filedir -d + if [ -e "$prev" ]; then + __docker_containers_all + COMPREPLY=( $( compgen -W "${COMPREPLY[*]}" -S ':' ) ) + __docker_nospace + else + _filedir + fi return fi ;;