Skip to content

Instantly share code, notes, and snippets.

@akarzim
Last active February 17, 2021 19:18
Show Gist options
  • Select an option

  • Save akarzim/6a0d679ef8e61d728be47bd7f47362de to your computer and use it in GitHub Desktop.

Select an option

Save akarzim/6a0d679ef8e61d728be47bd7f47362de to your computer and use it in GitHub Desktop.

Revisions

  1. akarzim revised this gist Dec 23, 2018. 1 changed file with 15 additions and 3 deletions.
    18 changes: 15 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -10,10 +10,22 @@ Defines [Docker][1] aliases and functions.
    - `dkE!` Run an interactive command in a running container by name
    - `dkps!` Display the first matching docker container ID by name

    ## How to use

    ### With [zplug][2]

    ```sh
    zplug "akarzim/6a0d679ef8e61d728be47bd7f47362de", \
    from:gist, \
    use:"zsh-docker-bang-aliases.zsh", \
    if:"(( $+commands[docker] ))"
    ```

    ## Acknowledgements

    Please consider [akarzim/zsh-docker-aliases][2] by [François Vantomme][3] (MIT License).
    Please consider [akarzim/zsh-docker-aliases][3] by [François Vantomme][4] (MIT License).

    [1]: https://www.docker.com/
    [2]: https://github.com/akarzim/zsh-docker-aliases
    [3]: https://github.com/akarzim
    [2]: https://github.com/zplug/zplug
    [3]: https://github.com/akarzim/zsh-docker-aliases
    [4]: https://github.com/akarzim
  2. akarzim created this gist Dec 23, 2018.
    19 changes: 19 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # ZSH Docker Aliases

    Defines [Docker][1] aliases and functions.

    ## Aliases

    ### Docker

    - `dka!` Attach to a running container by name
    - `dkE!` Run an interactive command in a running container by name
    - `dkps!` Display the first matching docker container ID by name

    ## Acknowledgements

    Please consider [akarzim/zsh-docker-aliases][2] by [François Vantomme][3] (MIT License).

    [1]: https://www.docker.com/
    [2]: https://github.com/akarzim/zsh-docker-aliases
    [3]: https://github.com/akarzim
    23 changes: 23 additions & 0 deletions zsh-docker-bang-aliases.zsh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # Display the first matching docker container ID by name
    #
    # Usage: dkps! app
    # > docker ps -f "name=app" -f "status=running" -q | head -n 1
    function dkps! {
    docker ps -f "name=$1" -f "status=running" -q | head -n 1
    }

    # Attatch docker by container partial name
    #
    # Usage: dka! app
    # > docker attach $(docker ps -f "name=app" -f "status=running" -q | head -n 1)
    function dka! {
    docker attach $(dkps! $1)
    }

    # Exec docker interactive command by container partial name
    #
    # Usage: dkE! app bash
    # > docker exec -e COLUMNS=`tput cols` -e LINES=`tput lines` -it $(docker ps -f "name=app" -f "status=running" -q | head -n 1) bash
    function dkE! {
    docker exec -e COLUMNS=`tput cols` -e LINES=`tput lines` -it $(dkps! $1) $*[2,$]
    }