fix(docker): handle empty container list in dsta alias

The `dsta` alias (stop all running containers) previously used
`docker stop $(docker ps -q)` which would fail with a usage error
when no containers were running, since `docker stop` requires at
least one argument.

Convert the alias to a function that checks if there are running
containers before attempting to stop them, and prints a helpful
message when no containers are running.
This commit is contained in:
fauzan171 2026-06-06 23:30:06 +07:00
parent 70ad5e3df8
commit 7a8a540160

View File

@ -29,8 +29,17 @@ alias 'drm!'='docker container rm -f'
alias dsprune='docker system prune'
alias dst='docker container start'
alias drs='docker container restart'
alias dsta='docker stop $(docker ps -q)'
alias dstp='docker container stop'
# Function to stop all running containers (handles empty list gracefully)
function dsta() {
local containers
containers=(${(f)"$(docker ps -q)"})
if (( ${#containers} > 0 )); then
docker stop "${containers[@]}"
else
echo "docker: no running containers to stop"
fi
}
alias dsts='docker stats'
alias dtop='docker top'
alias dvi='docker volume inspect'