Created
April 19, 2026 18:09
-
-
Save horaciod/3df1eceed1f441a4d2b9d6e37c4a2408 to your computer and use it in GitHub Desktop.
show information using fzf and bash from dockers running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### function to add to .bashrc | |
| fcompose() { | |
| # Comando para extraer la ruta del YAML | |
| local GET_YAML_CMD="docker inspect {1} --format '{{ index .Config.Labels \"com.docker.compose.project.config_files\" }}'" | |
| # PREVIEW_CMD: Ahora incluye la RUTA al principio | |
| local PREVIEW_CMD="echo -e '\e[1;34m--- RUTA YAML ---\e[0m'; \ | |
| $GET_YAML_CMD; \ | |
| echo -e '\n\e[1;36m--- REDES ---\e[0m'; \ | |
| docker inspect {1} --format '{{range \$net, \$conf := .NetworkSettings.Networks}}- {{ \$net }} ({{ \$conf.IPAddress }}){{println}}{{end}}'; \ | |
| echo -e '\n\e[1;36m--- PUERTOS (Host -> Contenedor) ---\e[0m'; \ | |
| docker inspect {1} --format '{{range \$p, \$conf := .NetworkSettings.Ports}}{{range \$conf}}{{ .HostIp }}:{{ .HostPort }} -> {{ \$p }}{{println}}{{end}}{{else}}Sin puertos mapeados{{end}}'; \ | |
| echo -e '\n\e[1;36m--- VOLÚMENES ---\e[0m'; \ | |
| docker inspect {1} --format '{{range .Mounts}}- {{.Source}} -> {{.Destination}}{{println}}{{end}}'" | |
| local TMP_FILE=$(mktemp) | |
| local SELECTION=$(docker ps --format "{{.Names}}" | fzf \ | |
| --height 80% \ | |
| --reverse \ | |
| --header "ENTER: Ver ruta | CTRL-Y: Ver contenido YAML | CTRL-V: Ir a Vol | ESC: Salir" \ | |
| --preview "$PREVIEW_CMD" \ | |
| --preview-window=right:65%:wrap \ | |
| --bind "ctrl-y:preview(echo -e '\e[1;33m--- CONTENIDO DEL ARCHIVO ---\e[0m\n'; cat \$($GET_YAML_CMD))" \ | |
| --bind "ctrl-v:execute(docker inspect {1} --format '{{range .Mounts}}{{if .Source}}{{.Source}}{{println}}{{end}}{{end}}' | head -n 1 > $TMP_FILE)+abort") | |
| # Lógica de salto a volumen (CTRL-V) | |
| if [ -s "$TMP_FILE" ]; then | |
| local DEST_DIR=$(cat "$TMP_FILE") | |
| rm "$TMP_FILE" | |
| if [ -d "$DEST_DIR" ]; then | |
| cd "$DEST_DIR" && echo -e "\n\033[1;32m📂 Saltando a:\033[0m $DEST_DIR" | |
| return | |
| elif [ -f "$DEST_DIR" ]; then | |
| cd "$(dirname "$DEST_DIR")" && echo -e "\n\033[1;32m📂 Saltando al directorio del archivo:\033[0m $(dirname "$DEST_DIR")" | |
| return | |
| fi | |
| fi | |
| # Lógica de salida estándar (ENTER) | |
| if [ -n "$SELECTION" ]; then | |
| local COMPOSE_PATH=$(docker inspect --format '{{ index .Config.Labels "com.docker.compose.project.config_files" }}' "$SELECTION" 2>/dev/null) | |
| echo -e "\n\033[1;32m✔ Contenedor:\033[0m $SELECTION" | |
| echo -e "\033[1;34m✔ Archivo YAML:\033[0m $COMPOSE_PATH" | |
| fi | |
| [ -f "$TMP_FILE" ] && rm "$TMP_FILE" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment