Can I alias a subcommand? (shortening the output of `docker ps`)

后端 未结 3 794
别那么骄傲
别那么骄傲 2020-11-27 20:52

The docker command has a ps sub-command that emits very long lines:

$ docker ps -a
CONTAINER ID        IMAGE                                


        
3条回答
  •  一个人的身影
    2020-11-27 21:02

    You can alias subcommands. With aliasing, you still get the nice zsh completions as if you were typing the full command. That's why I prefer them over functions.

    The equivalent of your alias is:

    alias dp='docker ps --format "table {{.Image}}\t{{.Names}}\t{{.Ports}}'\t{{.Status}}"
    

    But the full commands seem to now be recommended, and ls has replaced ps, which makes your alias now:

    alias dp='docker container ls --format "table {{.Image}}\t{{.Names}}\t{{.Ports}}'\t{{.Status}}"
    

    It's nice to have docker aliases for everything. For this, I've been working on a set of comprehensive aliases, which would have your alias as something like:

    alias ddcls='docker container ls --format "table {{.Image}}\t{{.Names}}\t{{.Ports}}\t{{.Status}}"
    

提交回复
热议问题