소스 검색

Merge pull request #11904 from albers/completion-filters

Add missing filters to bash completion for docker images and docker ps
Jessie Frazelle 10 년 전
부모
커밋
1ce39e234c
1개의 변경된 파일34개의 추가작업 그리고 6개의 파일을 삭제
  1. 34 6
      contrib/completion/bash/docker

+ 34 - 6
contrib/completion/bash/docker

@@ -58,6 +58,18 @@ __docker_containers_unpauseable() {
 	__docker_containers_all '.State.Paused'
 	__docker_containers_all '.State.Paused'
 }
 }
 
 
+__docker_container_names() {
+	local containers=( $(__docker_q ps -aq --no-trunc) )
+	local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
+	names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
+	COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
+}
+
+__docker_container_ids() {
+	local containers=( $(__docker_q ps -aq) )
+	COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
+}
+
 __docker_image_repos() {
 __docker_image_repos() {
 	local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
 	local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
 	COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
 	COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
@@ -437,7 +449,10 @@ _docker_history() {
 _docker_images() {
 _docker_images() {
 	case "$prev" in
 	case "$prev" in
 		--filter|-f)
 		--filter|-f)
-			COMPREPLY=( $( compgen -W "dangling=true" -- "$cur" ) )
+			COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) )
+			if [ "$COMPREPLY" = "label=" ]; then
+				compopt -o nospace
+			fi
 			return
 			return
 			;;
 			;;
 	esac
 	esac
@@ -447,17 +462,20 @@ _docker_images() {
 			COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) )
 			COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) )
 			return
 			return
 			;;
 			;;
+		*label=*)
+			return
+			;;
 	esac
 	esac
 
 
 	case "$cur" in
 	case "$cur" in
 		-*)
 		-*)
 			COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
 			COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
 			;;
 			;;
+		=)
+			return
+			;;
 		*)
 		*)
-			local counter=$(__docker_pos_first_nonflag)
-			if [ $cword -eq $counter ]; then
-				__docker_image_repos
-			fi
+			__docker_image_repos
 			;;
 			;;
 	esac
 	esac
 }
 }
@@ -616,7 +634,7 @@ _docker_ps() {
 			__docker_containers_all
 			__docker_containers_all
 			;;
 			;;
 		--filter|-f)
 		--filter|-f)
-			COMPREPLY=( $( compgen -S = -W "exited status" -- "$cur" ) )
+			COMPREPLY=( $( compgen -S = -W "exited id label name status" -- "$cur" ) )
 			compopt -o nospace
 			compopt -o nospace
 			return
 			return
 			;;
 			;;
@@ -626,6 +644,16 @@ _docker_ps() {
 	esac
 	esac
 
 
 	case "${words[$cword-2]}$prev=" in
 	case "${words[$cword-2]}$prev=" in
+		*id=*)
+			cur="${cur#=}"
+			__docker_container_ids
+			return
+			;;
+		*name=*)
+			cur="${cur#=}"
+			__docker_container_names
+			return
+			;;
 		*status=*)
 		*status=*)
 			COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) )
 			COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) )
 			return
 			return