The output of the docker ps command is super useful but can be unwieldy. Especially on a smaller terminal window.

Turns out there’s a cool builtin called tput that provides env info on a terminal session.

tput cols

tput lines
# aka rows

Here’s a “better” docker ps for a bash profile:

function dockerps() {
  [[ $(tput cols) -lt 100 ]] && { docker ps --format "table {{.Names}}\t{{.Ports}}"; return;}

  [[ $(tput cols) -lt 150 ]] && { docker ps --format "table {{.ID}}\t{{.Names}}\t{{.RunningFor}}\t{{.Ports}}"; return; }

  docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.RunningFor}}\t{{.Ports}}"
}

Now typing dockerps as one word will provide more readable output based on the terminal size.