Browse code

Fix fish autocompletion with custom ps output

In the docker config.json, if `psFormat` or `imagesFormat` is set to a
non-standard format, it breaks autocompletion.

This fixes the issue by using a custom format.

Signed-off-by: Chris Gibson <chris@chrisg.io>

Chris Gibson authored on 2017/03/08 15:19:45
Showing 1 changed files
... ...
@@ -26,20 +26,20 @@ end
26 26
 function __fish_print_docker_containers --description 'Print a list of docker containers' -a select
27 27
     switch $select
28 28
         case running
29
-            docker ps -a --no-trunc | command awk 'NR>1' | command awk 'BEGIN {FS="  +"}; $5 ~ "^Up" {print $1 "\n" $(NF)}' | tr ',' '\n'
29
+            docker ps -a --no-trunc --filter status=running --format "{{.ID}}\n{{.Names}}" | tr ',' '\n'
30 30
         case stopped
31
-            docker ps -a --no-trunc | command awk 'NR>1' | command awk 'BEGIN {FS="  +"}; $5 ~ "^Exit" {print $1 "\n" $(NF)}' | tr ',' '\n'
31
+            docker ps -a --no-trunc --filter status=exited --format "{{.ID}}\n{{.Names}}" | tr ',' '\n'
32 32
         case all
33
-            docker ps -a --no-trunc | command awk 'NR>1' | command awk 'BEGIN {FS="  +"}; {print $1 "\n" $(NF)}' | tr ',' '\n'
33
+            docker ps -a --no-trunc --format "{{.ID}}\n{{.Names}}" | tr ',' '\n'
34 34
     end
35 35
 end
36 36
 
37 37
 function __fish_print_docker_images --description 'Print a list of docker images'
38
-    docker images | command awk 'NR>1' | command grep -v '<none>' | command awk '{print $1":"$2}'
38
+    docker images --format "{{.Repository}}:{{.Tag}}" | command grep -v '<none>'
39 39
 end
40 40
 
41 41
 function __fish_print_docker_repositories --description 'Print a list of docker repositories'
42
-    docker images | command awk 'NR>1' | command grep -v '<none>' | command awk '{print $1}' | command sort | command uniq
42
+    docker images --format "{{.Repository}}" | command grep -v '<none>' | command sort | command uniq
43 43
 end
44 44
 
45 45
 # common options