Skip to content

Commit 59fb137

Browse files
author
Sengorius
committed
added a configurable format for "DockerExec do ps" command
1 parent 0e0906e commit 59fb137

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

.env.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ export ATTACH_TO_COMPOSE_LOGS=1
2323

2424
# the name of the local Docker network for this proxy-stack
2525
export NETWORK_NAME=proxy-network
26+
27+
# tell "DockerExec do ps" what columns to print out; separate with a pipe
28+
# possible values are: ID, Image, Command, CreatedAt, RunningFor, Ports,
29+
# State, Status, Size, Names, Labels, Mounts and Networks
30+
# see https://docs.docker.com/engine/reference/commandline/ps/#formatting
31+
export DOCKER_PS_COLUMNS="Image|Status|Ports|Names"

DockerExec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,12 @@ elif [[ "do" == "$ENVIRONMENT" ]]; then
518518

519519
# shortcut to list all docker containers
520520
elif [[ "ps" == "$ACTION" ]]; then
521-
docker ps -a --format "table {{.Image}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}"
521+
PS_COLUMNS=${DOCKER_PS_COLUMNS:-Image|Status|Ports|Names}
522+
PS_COLUMNS=${PS_COLUMNS//|/ }
523+
PS_COLUMNS_FORMATTED=$(join_by '}}\t{{.' $PS_COLUMNS)
524+
PS_FORMAT="table {{.$PS_COLUMNS_FORMATTED}}"
525+
526+
docker ps -a --format "$PS_FORMAT"
522527

523528
else
524529
print_error "Unknown option '$ACTION'..." 1

src/helpers.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,14 @@ function import_to_database_container() {
187187
docker exec -it "$CONTAINER_NAME" bash -c "$COMMAND" && \
188188
print_info "Import complete." 1
189189
}
190+
191+
# joins an input by given glue on first parameter
192+
# usage: join_by ', ' a b c d
193+
function join_by() {
194+
local d=${1-}
195+
local f=${2-}
196+
197+
if shift 2; then
198+
printf %s "$f" "${@/#/$d}"
199+
fi
200+
}

0 commit comments

Comments
 (0)