Add docker exec + fzf function

This commit is contained in:
Jeremy Gardais 2023-01-17 14:46:37 +01:00
parent 0196f51b32
commit e62370ffe8
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 20 additions and 0 deletions

20
zshrc
View File

@ -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