diff --git a/zshrc b/zshrc index fa3d09f..e40a011 100644 --- a/zshrc +++ b/zshrc @@ -2372,6 +2372,26 @@ fopen() { } # }}} +# dexec − Docker exec in a running container {{{ +# Display Docker running containers +# Allow to specify the shell (default to bash) +dexec() { + local images_name + local container_name + local container_id + + images_name=$(docker container ls --format "table {{.Image}}\t {{.RunningFor}}\t {{.Ports}}\t {{.Names}}" | fzf --prompt='docker> ' --tac ) + + ## Extract container_name from the selected line + container_name=$(printf '%b' "${images_name}" | awk '{ print $NF }') + ## Get container_id from the selected container_name + container_id=$(docker container ls --quiet --filter=name="${container_name}") + + printf "%b\n" "Try to enter to Docker container (named : ${container_name})" + docker exec -it "${container_id:-/dev/null}" "${1:-bash}" +} +# }}} + # }}} # zsh-syntax-highlighting {{{ ## Activate if plugin is available