Skip to content

Instantly share code, notes, and snippets.

@AgustinParmisano
Created November 17, 2025 20:32
Show Gist options
  • Select an option

  • Save AgustinParmisano/9794443b4faa16a339ae087a9055e60d to your computer and use it in GitHub Desktop.

Select an option

Save AgustinParmisano/9794443b4faa16a339ae087a9055e60d to your computer and use it in GitHub Desktop.
cat with fzf type filter
#!/bin/bash
show_help() {
echo "Uso: fcat <archivo>"
echo "Muestra el contenido de un archivo usando fzf para navegación interactiva"
echo ""
echo "Ejemplos:"
echo " fcat salario.txt"
echo " fcat /var/log/syslog"
}
# Verificar dependencias
check_deps() {
if ! command -v rg &> /dev/null; then
echo "Error: ripgrep (rg) no está instalado"
exit 1
fi
if ! command -v fzf &> /dev/null; then
echo "Error: fzf no está instalado"
exit 1
fi
}
main() {
# Mostrar ayuda si se solicita
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
show_help
exit 0
fi
# Verificar parámetros
if [[ $# -eq 0 ]]; then
echo "Error: Se requiere un archivo como parámetro"
show_help
exit 1
fi
local archivo="$1"
# Verificar que el archivo existe
if [[ ! -f "$archivo" ]]; then
echo "Error: El archivo '$archivo' no existe"
exit 1
fi
# Verificar dependencias
check_deps
# Ejecutar búsqueda interactiva
rg --color=always --line-number "" "$archivo" | fzf \
--ansi \
--delimiter ":" \
--nth 2.. \
--no-sort \
--bind "ctrl-d:preview-page-down,ctrl-u:preview-page-up" \
--header "Navegando: $archivo | ←↑↓→ para navegar | Enter para seleccionar"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment