Created
September 22, 2015 21:30
-
-
Save frodopwns/19e1950ba643843f69be to your computer and use it in GitHub Desktop.
pretty print docker ps commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import json | |
import sys | |
import os | |
from subprocess import Popen, PIPE | |
if __name__ == '__main__': | |
base_path = os.path.abspath(os.path.dirname(__file__)) | |
args = sys.argv | |
# call tests | |
a = Popen("docker ps %s" % " ".join(args[1:]), stdout=PIPE, stderr=PIPE, shell=True) | |
# wait for them to finish | |
astdout, astderr = a.communicate() | |
data = astdout.split("\n") | |
data = filter(None, data) | |
header = re.split(r'\s{2,}', data[0]) | |
rows = data[1:] | |
rows = [re.split(r'\s{2,}', x.strip()) for x in rows] | |
for row in rows: | |
print json.dumps(dict(zip(header, row)), indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been using this, it can be put into your
.bash_profile
or.bashrc
file that works somewhat like an alias for docker ps. The output has color distinctions as well:usage: $ docker ps -p