-
-
Save AgustinParmisano/9794443b4faa16a339ae087a9055e60d to your computer and use it in GitHub Desktop.
cat with fzf type filter
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
| #!/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