1

I want to override the docker command so that when I do docker ps or docker service ls exactly it will render in the format I want.

I started with this

docker() {
  if [ "$*" == 'ps' ]
  then
    command docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
  else
    eval "command docker $*"
    # eval "command docker $@"
    # command docker $*
    # command docker $@
    # command docker "$*"
  fi
}

However when I did it this does not work

docker service ls --format="table {{.Name}}\t{{.Image}}\t{{.Replicas}}\t{{.Ports}}"

But

command docker service ls --format="table {{.Name}}\t{{.Image}}\t{{.Replicas}}\t{{.Ports}}"

It appears to be because of the " characters being processed.

Archimedes Trajano
  • 28,830
  • 14
  • 134
  • 195

1 Answers1

3

Use "$@" rather than $* to ensure that arguments are re-quoted.

docker() {
  if [ "$*" = 'ps' ]
  then
    command docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
  else
    command docker "$@"
  fi
}
Barmar
  • 669,327
  • 51
  • 454
  • 560