Skip to content

Commit

Permalink
add fzf docker functions
Browse files Browse the repository at this point in the history
  • Loading branch information
victory-sokolov committed Dec 29, 2023
1 parent aec5dbc commit 6757240
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions zsh/.dockerfunc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,43 @@ function docker-stop # Stop all containers
docker stop $(docker container ls -q)
}

function da() # Select a docker container to start and attach to
{
local cid
cid=$(docker ps -a | sed 1d | fzf -1 -q "$1" | awk '{print $1}')

[ -n "$cid" ] && docker start "$cid" && docker attach "$cid"
}

dlogs() # Check logs of container
{
# Get a list of running Docker container names
local container_names=$(docker ps --format '{{.Names}}')

# Use fzf to interactively select a container
local selected_container=$(echo "$container_names" | fzf --prompt="Select a Docker container: ")

# Check if a container was selected
if [ -n "$selected_container" ]; then
# Show logs for the selected container
docker logs -f "$selected_container"
else
echo "No container selected."
fi
}

function drm() # Select a docker container to remove
{
docker ps -a | sed 1d | fzf -q "$1" --no-sort -m --tac | awk '{ print $1 }' | xargs -r docker rm
}

function ds() # Select a running docker container to stop
{
local cid
cid=$(docker ps | sed 1d | fzf -q "$1" | awk '{print $1}')

[ -n "$cid" ] && docker stop "$cid"
}

function drmprefix() # Remove all containers named with the given prefix
{
Expand Down

0 comments on commit 6757240

Please sign in to comment.