Files
egutierrez 8f45b40528 feat: add bash shell utility functions
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.
2026-04-12 13:54:15 +02:00

65 lines
1.3 KiB
Bash

# bash_log
# --------
# Funciones de logging con colores para scripts.
# Incluye: log, success, info, warning, error, debug, progress.
#
# USO (sourced):
# source bash_log.sh
# bash_log_init
# success "Operacion completada"
# info "Procesando..."
# error "Algo fallo"
SCRIPT_DIR_BASH_LOG="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR_BASH_LOG/bash_colors.sh"
bash_colors
bash_log_init() {
export ERROR_LOG_FILE="${ERROR_LOG_FILE:-/tmp/script-errors-$(date +%Y%m%d).log}"
export DEBUG_MODE="${DEBUG_MODE:-0}"
}
log() {
local level="$1"
shift
local message="$@"
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] [$level] $message" >> "${ERROR_LOG_FILE:-/tmp/script-errors.log}"
if [ "${DEBUG_MODE:-0}" = "1" ]; then
echo -e "${GRAY}[$timestamp] [$level] $message${NC}" >&2
fi
}
success() {
echo -e "${GREEN}${CHECKMARK} $*${NC}"
log "SUCCESS" "$*"
}
info() {
echo -e "${BLUE}${INFO} $*${NC}"
log "INFO" "$*"
}
warning() {
echo -e "${YELLOW}${WARNING} $*${NC}"
log "WARNING" "$*"
}
error() {
echo -e "${RED}${CROSS} Error: $*${NC}" >&2
log "ERROR" "$*"
}
debug() {
if [ "${DEBUG_MODE:-0}" = "1" ]; then
echo -e "${GRAY}[DEBUG] $*${NC}" >&2
fi
log "DEBUG" "$*"
}
progress() {
echo -e "${CYAN}${ARROW} $*${NC}"
}