add docker-services function/alias
This commit is contained in:
@@ -8,7 +8,7 @@ grep -E "set .port|server_name" /app/nginxproxy/data/nginx/proxy_host/*.conf \
|
|||||||
| sort -n \
|
| sort -n \
|
||||||
| column -t -N "PORT,TARGET,OTHER_TARGET" -W "OTHER_TARGET" -s ' ' -o ' | ';
|
| column -t -N "PORT,TARGET,OTHER_TARGET" -W "OTHER_TARGET" -s ' ' -o ' | ';
|
||||||
}
|
}
|
||||||
alias ports='_ports'
|
alias nginx='_ports'
|
||||||
|
|
||||||
# tmp rebuild for hugo development
|
# tmp rebuild for hugo development
|
||||||
alias hugo-rebuild='rm -rf public/ && hugo server --appendPort=false --baseURL="/" --ignoreCache'
|
alias hugo-rebuild='rm -rf public/ && hugo server --appendPort=false --baseURL="/" --ignoreCache'
|
||||||
@@ -61,3 +61,47 @@ function _tagger() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
alias tag='_tagger'
|
alias tag='_tagger'
|
||||||
|
|
||||||
|
# docker services
|
||||||
|
function _docker-table() {
|
||||||
|
if ! docker info > /dev/null 2>&1; then
|
||||||
|
echo "Error: Docker daemon is not running."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
(
|
||||||
|
# 1. Adjusted Header to match your 3 requested columns
|
||||||
|
printf "NAME|STATUS|EXPOSED PORTS\n"
|
||||||
|
|
||||||
|
# 2. Match the format string to exactly what you are reading
|
||||||
|
docker ps -a --format "{{.Names}}|{{.Status}}|{{.Ports}}" | while IFS='|' read -r name status ports; do
|
||||||
|
if [ -n "$ports" ]; then
|
||||||
|
# Split ports strictly by comma
|
||||||
|
IFS=',' read -r -a port_array <<< "$ports"
|
||||||
|
cleaned_ports=""
|
||||||
|
|
||||||
|
for p in "${port_array[@]}"; do
|
||||||
|
# Trim any leading/trailing spaces from the array element
|
||||||
|
p=$(echo "$p" | xargs)
|
||||||
|
|
||||||
|
# Strip everything up to and including '->' if it exists
|
||||||
|
cleaned_p="${p##*->}"
|
||||||
|
|
||||||
|
# Prevent duplicate listings (e.g. if IPv4 and IPv6 both map to 8080/tcp)
|
||||||
|
if [[ ", $cleaned_ports, " != *", $cleaned_p, "* ]]; then
|
||||||
|
if [ -z "$cleaned_ports" ]; then
|
||||||
|
cleaned_ports="$cleaned_p"
|
||||||
|
else
|
||||||
|
cleaned_ports="$cleaned_ports, $cleaned_p"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
ports="$cleaned_ports"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Print the 3 columns cleanly
|
||||||
|
printf "%s|%s|%s\n" "$name" "$status" "$ports"
|
||||||
|
done
|
||||||
|
) | column -t -s '|'
|
||||||
|
}
|
||||||
|
alias docker-services='_docker-table'
|
||||||
|
|||||||
Reference in New Issue
Block a user