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.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# bash_confirm
|
||||
# ------------
|
||||
# Dialogo de confirmacion y/n con valor por defecto.
|
||||
#
|
||||
# USO (sourced):
|
||||
# source bash_confirm.sh
|
||||
# bash_confirm "Continuar?" && echo "Si" || echo "No"
|
||||
# bash_confirm "Eliminar?" "y" # default yes
|
||||
|
||||
SCRIPT_DIR_BASH_CONFIRM="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR_BASH_CONFIRM/bash_colors.sh"
|
||||
bash_colors
|
||||
|
||||
bash_confirm() {
|
||||
local prompt="${1:-¿Continuar?}"
|
||||
local default="${2:-n}"
|
||||
|
||||
if [ "$default" = "y" ]; then
|
||||
prompt="$prompt [Y/n]"
|
||||
else
|
||||
prompt="$prompt [y/N]"
|
||||
fi
|
||||
|
||||
echo -ne "${YELLOW}$prompt ${NC}"
|
||||
read -r response
|
||||
|
||||
response=${response:-$default}
|
||||
case "$response" in
|
||||
[yY][eE][sS]|[yY]|[sS][iI])
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
Reference in New Issue
Block a user