Browse code

bash completion for `--detach-keys`

Signed-off-by: Harald Albers <github@albersweb.de>

Harald Albers authored on 2016/01/15 05:47:48
Showing 1 changed files
... ...
@@ -340,6 +340,25 @@ __docker_complete_capabilities() {
340 340
 	" -- "$cur" ) )
341 341
 }
342 342
 
343
+__docker_complete_detach-keys() {
344
+	case "$prev" in
345
+		--detach-keys)
346
+			case "$cur" in
347
+				*,)
348
+					COMPREPLY=( $( compgen -W "${cur}ctrl-" -- "$cur" ) )
349
+					;;
350
+				*)
351
+					COMPREPLY=( $( compgen -W "ctrl-" -- "$cur" ) )
352
+					;;
353
+			esac
354
+
355
+			__docker_nospace
356
+			return
357
+			;;
358
+	esac
359
+	return 1
360
+}
361
+
343 362
 __docker_complete_isolation() {
344 363
 	COMPREPLY=( $( compgen -W "default hyperv process" -- "$cur" ) )
345 364
 }
... ...
@@ -513,12 +532,14 @@ _docker_docker() {
513 513
 }
514 514
 
515 515
 _docker_attach() {
516
-	case "$cur" in
516
+	__docker_complete_detach-keys && return
517
+
518
+ 	case "$cur" in
517 519
 		-*)
518
-			COMPREPLY=( $( compgen -W "--help --no-stdin --sig-proxy" -- "$cur" ) )
520
+			COMPREPLY=( $( compgen -W "--detach-keys --help --no-stdin --sig-proxy" -- "$cur" ) )
519 521
 			;;
520 522
 		*)
521
-			local counter="$(__docker_pos_first_nonflag)"
523
+			local counter=$(__docker_pos_first_nonflag '--detach-keys')
522 524
 			if [ $cword -eq $counter ]; then
523 525
 				__docker_complete_containers_running
524 526
 			fi
... ...
@@ -901,6 +922,8 @@ _docker_events() {
901 901
 }
902 902
 
903 903
 _docker_exec() {
904
+	__docker_complete_detach-keys && return
905
+
904 906
 	case "$prev" in
905 907
 		--user|-u)
906 908
 			return
... ...
@@ -909,7 +932,7 @@ _docker_exec() {
909 909
 
910 910
 	case "$cur" in
911 911
 		-*)
912
-			COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
912
+			COMPREPLY=( $( compgen -W "--detach -d --detach-keys --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
913 913
 			;;
914 914
 		*)
915 915
 			__docker_complete_containers_running
... ...
@@ -1508,13 +1531,20 @@ _docker_run() {
1508 1508
 		--tty -t
1509 1509
 	"
1510 1510
 
1511
+	if [ "$command" = "run" ] ; then
1512
+		options_with_args="$options_with_args
1513
+			--detach-keys
1514
+		"
1515
+		boolean_options="$boolean_options
1516
+			--detach -d
1517
+			--rm
1518
+			--sig-proxy=false
1519
+		"
1520
+		__docker_complete_detach-keys && return
1521
+	fi
1522
+
1511 1523
 	local all_options="$options_with_args $boolean_options"
1512 1524
 
1513
-	[ "$command" = "run" ] && all_options="$all_options
1514
-		--detach -d
1515
-		--rm
1516
-		--sig-proxy=false
1517
-	"
1518 1525
 
1519 1526
 	case "$prev" in
1520 1527
 		--add-host)
... ...
@@ -1701,9 +1731,11 @@ _docker_search() {
1701 1701
 }
1702 1702
 
1703 1703
 _docker_start() {
1704
+	__docker_complete_detach-keys && return
1705
+
1704 1706
 	case "$cur" in
1705 1707
 		-*)
1706
-			COMPREPLY=( $( compgen -W "--attach -a --help --interactive -i" -- "$cur" ) )
1708
+			COMPREPLY=( $( compgen -W "--attach -a --detach-keys --help --interactive -i" -- "$cur" ) )
1707 1709
 			;;
1708 1710
 		*)
1709 1711
 			__docker_complete_containers_stopped