Mikescher / better-docker-ps

Because `docker ps` is annoying and does not fit my monitor/terminal width
MIT License
119 stars 3 forks source link

allow formatting with golang templates (ie to truncate) #9

Closed AskAlice closed 3 months ago

AskAlice commented 3 months ago

I have a few docker swarm containers that really clog up the width. I tried using a golang template to truncate the output, however this did not work. https://stackoverflow.com/a/36093426/643875

dops --format "table {{.ID}}\\t{{ slice .Names 0 16 }}\\t{{.State}}"  --format "table {{.ID}}\\t{{.Names}}" --format "table {{.ID}}"

CONTAINER ID    {{ slice .Names 0 16 }}    STATE
------------    -----------------------    ---------
c9290b9329af    {{ slice .Names 0 16 }}    [RUNNING]
00c7c4113510    {{ slice .Names 0 16 }}    [RUNNING]
05c2e845abb4    {{ slice .Names 0 16 }}    [RUNNING]
c36308698e28    {{ slice .Names 0 16 }}    [RUNNING]
12cdc8507451    {{ slice .Names 0 16 }}    [RUNNING]
8949cb99da26    {{ slice .Names 0 16 }}    [RUNNING]
d5d1b1442d01    {{ slice .Names 0 16 }}    [RUNNING]
a4150fa54b74    {{ slice .Names 0 16 }}    [RUNNING]
3915d3e3a58e    {{ slice .Names 0 16 }}    [RUNNING]
9cfebb0532a8    {{ slice .Names 0 16 }}    [RUNNING]
NAME                                                                  PUBLISHED PORTS         IMAGE                                                                                            STATUS
------------------------------------------------------------------    --------------------    ---------------------------------------------------------------------------------------------    -------------
swarmpit_agent.msfm2wcpsfmhmvynbkmd6d49z.u2lmmx02ut1edo63wsnjlqugh                            swarmpit/agent:latest@sha256:f92ba65f7923794d43ebffc88fbd49bfe8cde8db48ca6888ece5747b9ab1375c    Up 47 minutes
dnsmasq                                                                  53 ->    53 / udp    jpillora/dnsmasq                                                                                 Up 47 minutes
                                                                       5380 ->  8080 / tcp
grafana                                                                3333 ->  3000 / tcp    grafana/grafana:latest                                                                           Up 47 minutes
fitbit-fetch-data                                                                             thisisarpanghosh/fitbit-fetch-data:latest                                                        Up 47 minutes
influxdb                                                               3334 ->  8086 / tcp    influxdb:2.7.6                                                                                   Up 47 minutes
mongoku                                                                8081 ->  3100 / tcp    huggingface/mongoku                                                                              Up 47 minutes
ritmongo                                                              27017 -> 27017 / tcp    mongo                                                                                            Up 47 minutes
search                                                                 3006 ->  8080 / tcp    search                                                                                           Up 47 minutes
mongoku2                                                               8086 ->  3100 / tcp    huggingface/mongoku                                                                              Up 47 minutes
Mikescher commented 3 months ago

Yeah, they were not fully-featured go template placeholder.

I changed it and now you should be able to write any valid go-template code in the format string.

Will be included in the next release

(see README for the syntax)