8f45b40528
12 funciones Bash del dominio shell: utilidades de scripting (bash_log, bash_colors, bash_check_deps, bash_confirm, bash_handle_error, bash_safe_run), manipulacion de texto (convert_text_case), estructura de proyectos (create_project_structure), y operaciones git (git_clean_branches, git_log_visual, git_push_all_remotes, git_repo_status). Cada una con su .sh y .md de frontmatter.
76 lines
2.0 KiB
Bash
76 lines
2.0 KiB
Bash
#!/usr/bin/env bash
|
|
# git_log_visual
|
|
# --------------
|
|
# Muestra el historial de commits con grafo visual, colores y formato legible.
|
|
# Soporta filtros por cantidad, autor, fecha y todas las ramas.
|
|
#
|
|
# USO:
|
|
# source git_log_visual.sh
|
|
# git_log_visual [--count N] [--author X] [--since D] [--all]
|
|
#
|
|
# ARGUMENTOS:
|
|
# --count N Número de commits a mostrar (default: 20)
|
|
# --author X Filtrar por nombre o email del autor
|
|
# --since D Mostrar commits desde fecha (ej: "1 week ago", "2025-01-01")
|
|
# --all Incluir todas las ramas
|
|
|
|
git_log_visual() {
|
|
local count=20
|
|
local author=""
|
|
local since=""
|
|
local all_branches=false
|
|
|
|
# Parsear argumentos
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--count|-n)
|
|
count="$2"
|
|
shift 2
|
|
;;
|
|
--author|-a)
|
|
author="$2"
|
|
shift 2
|
|
;;
|
|
--since|-s)
|
|
since="$2"
|
|
shift 2
|
|
;;
|
|
--all)
|
|
all_branches=true
|
|
shift
|
|
;;
|
|
*)
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Validar repo
|
|
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
|
|
echo "git_log_visual: el directorio actual no es un repositorio Git" >&2
|
|
return 1
|
|
fi
|
|
|
|
local log_format="%C(yellow)%h%C(reset) %C(cyan)%ad%C(reset) %C(green)%an%C(reset) %s%C(red)%d%C(reset)"
|
|
|
|
# Construir argumentos del comando
|
|
local args=()
|
|
args+=("--graph")
|
|
args+=("--color=always")
|
|
args+=("--date=short")
|
|
args+=("--format=${log_format}")
|
|
args+=("-n" "${count}")
|
|
|
|
[[ -n "$author" ]] && args+=("--author=${author}")
|
|
[[ -n "$since" ]] && args+=("--since=${since}")
|
|
[[ "$all_branches" == true ]] && args+=("--all")
|
|
|
|
# Ejecutar
|
|
git log "${args[@]}" 2>/dev/null | less -R --quit-if-one-screen
|
|
}
|
|
|
|
# Ejecutar si se invoca directamente
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
git_log_visual "$@"
|
|
fi
|