Compare commits
4 Commits
3b79ed9ad6
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
7135dd6077
|
|||
|
0d88c91fc2
|
|||
|
53a8e4044b
|
|||
|
9d2ca59258
|
@@ -13,6 +13,7 @@ _init_git_symbols() {
|
||||
GIT_SYMBOLS[ahead]="↑"
|
||||
GIT_SYMBOLS[behind]="↓"
|
||||
GIT_SYMBOLS[diverged]="↕"
|
||||
GIT_SYMBOLS[no_upstream]="○"
|
||||
GIT_SYMBOLS[untracked]="?"
|
||||
GIT_SYMBOLS[added]="+"
|
||||
GIT_SYMBOLS[deleted]="D"
|
||||
@@ -48,6 +49,7 @@ _parse_git_status() {
|
||||
|
||||
# Get ahead/behind counts - use more reliable method
|
||||
if git rev-parse --abbrev-ref "@{upstream}" >/dev/null 2>&1; then
|
||||
GIT_STATUS[has_upstream]=1
|
||||
# Use separate commands for more reliable parsing
|
||||
GIT_STATUS[ahead]="$(git rev-list --count HEAD ^"@{upstream}" 2>/dev/null || echo 0)"
|
||||
GIT_STATUS[behind]="$(git rev-list --count "@{upstream}" ^HEAD 2>/dev/null || echo 0)"
|
||||
@@ -61,6 +63,7 @@ _parse_git_status() {
|
||||
fi
|
||||
fi
|
||||
else
|
||||
GIT_STATUS[has_upstream]=0
|
||||
GIT_STATUS[behind]=0
|
||||
GIT_STATUS[ahead]=0
|
||||
fi
|
||||
@@ -116,9 +119,15 @@ _get_git_status_fast() {
|
||||
|
||||
local output=""
|
||||
|
||||
# Check if completely clean (no dirty files AND no ahead/behind)
|
||||
if [[ ${GIT_STATUS[dirty]} -eq 0 && ${GIT_STATUS[ahead]} -eq 0 && ${GIT_STATUS[behind]} -eq 0 ]]; then
|
||||
echo -n "${BOLD}${GREEN}${GIT_SYMBOLS[clean]}${RESET}"
|
||||
# Check if completely clean (no dirty files AND no ahead/behind AND has upstream)
|
||||
if [[ ${GIT_STATUS[dirty]} -eq 0 && ${GIT_STATUS[ahead]} -eq 0 && ${GIT_STATUS[behind]} -eq 0 && ${GIT_STATUS[has_upstream]} -eq 1 ]]; then
|
||||
echo -n "${BOLD}${CYAN}${GIT_SYMBOLS[clean]}${RESET}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Check if clean but no upstream (local branch only)
|
||||
if [[ ${GIT_STATUS[dirty]} -eq 0 && ${GIT_STATUS[has_upstream]} -eq 0 ]]; then
|
||||
echo -n "${BOLD}${PURPLE}${GIT_SYMBOLS[no_upstream]}${RESET}"
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -128,12 +137,22 @@ _get_git_status_fast() {
|
||||
fi
|
||||
|
||||
# Add ahead/behind status with semantic colors
|
||||
if [[ ${GIT_STATUS[ahead]} -gt 0 && ${GIT_STATUS[behind]} -gt 0 ]]; then
|
||||
output+="${BOLD}${ORANGE}${GIT_SYMBOLS[diverged]}${GIT_STATUS[ahead]}/${GIT_STATUS[behind]}${RESET}"
|
||||
elif [[ ${GIT_STATUS[ahead]} -gt 0 ]]; then
|
||||
output+="${BOLD}${GREEN}${GIT_SYMBOLS[ahead]}${GIT_STATUS[ahead]}${RESET}"
|
||||
elif [[ ${GIT_STATUS[behind]} -gt 0 ]]; then
|
||||
output+="${BOLD}${RED}${GIT_SYMBOLS[behind]}${GIT_STATUS[behind]}${RESET}"
|
||||
if [[ ${GIT_STATUS[has_upstream]} -eq 1 ]]; then
|
||||
# Create pattern: "ahead_behind" (0=false, 1=true)
|
||||
local ahead_flag
|
||||
local behind_flag
|
||||
ahead_flag=$([[ ${GIT_STATUS[ahead]} -gt 0 ]] && echo "1" || echo "0")
|
||||
behind_flag=$([[ ${GIT_STATUS[behind]} -gt 0 ]] && echo "1" || echo "0")
|
||||
|
||||
case "${ahead_flag}${behind_flag}" in
|
||||
"11") output+="${BOLD}${ORANGE}${GIT_SYMBOLS[diverged]}${GIT_STATUS[ahead]}/${GIT_STATUS[behind]}${RESET}" ;;
|
||||
"10") output+="${BOLD}${GREEN}${GIT_SYMBOLS[ahead]}${GIT_STATUS[ahead]}${RESET}" ;;
|
||||
"01") output+="${BOLD}${RED}${GIT_SYMBOLS[behind]}${GIT_STATUS[behind]}${RESET}" ;;
|
||||
"00") ;; # Clean state, no additional symbol needed
|
||||
esac
|
||||
else
|
||||
# No upstream - show no-upstream indicator
|
||||
output+="${BOLD}${PURPLE}${GIT_SYMBOLS[no_upstream]}${RESET}"
|
||||
fi
|
||||
|
||||
# File status indicators with semantic colors
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
#!/bin/bash
|
||||
# shellcheck source=/dev/null
|
||||
|
||||
# Constants
|
||||
HYPERTERM_DIR="${HYPERTERM_DIR:-$HOME/.hyperterm}"
|
||||
URL_1="${URL_1:-https://git.fridu.us/heckyel/hyperterm}"
|
||||
URL_2="${URL_2:-https://c.fridu.us/software/hyperterm.git}"
|
||||
REPO_ERROR_MSG_ES="${REPO_ERROR_MSG_ES:-El repositorio no está disponible o no hay conexión a Internet.}"
|
||||
REPO_ERROR_MSG_EN="${REPO_ERROR_MSG_EN:-The repository is unavailable or there\'s no internet connection.}"
|
||||
|
||||
#----------------------------
|
||||
# Check if a command exists
|
||||
#----------------------------
|
||||
@@ -15,22 +23,16 @@ function _url_exists() {
|
||||
}
|
||||
|
||||
#------------------
|
||||
# Set working URLs
|
||||
# Get working URLs
|
||||
#------------------
|
||||
function _urls() {
|
||||
URL_1="https://git.fridu.us/heckyel/hyperterm"
|
||||
URL_2="https://c.fridu.us/software/hyperterm.git"
|
||||
|
||||
function _get_repo_urls() {
|
||||
if [ "$(_url_exists "$URL_1")" -eq 200 ]; then
|
||||
URL="$URL_1"
|
||||
RAW="$URL_1/raw/branch/master"
|
||||
echo "$URL_1|$URL_1/raw/branch/master"
|
||||
elif [ "$(_url_exists "$URL_2")" -eq 200 ]; then
|
||||
URL="$URL_2"
|
||||
RAW="$URL_2/plain"
|
||||
echo "$URL_2|$URL_2/plain"
|
||||
else
|
||||
msg_err "El repositorio no está disponible o no hay conexión a Internet." \
|
||||
"The repository is unavailable or there's no internet connection."
|
||||
exit 1
|
||||
msg_err "$REPO_ERROR_MSG_ES" "$REPO_ERROR_MSG_EN"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -40,44 +42,71 @@ function _urls() {
|
||||
function download_file() {
|
||||
local remote_path=$1
|
||||
local local_path=$2
|
||||
mkdir -p "$(dirname "$local_path")"
|
||||
curl -Ls "$RAW/$remote_path" -o "$local_path"
|
||||
local repo_info
|
||||
local raw_url
|
||||
|
||||
repo_info=$(_get_repo_urls) || return 1
|
||||
raw_url="${repo_info#*|}"
|
||||
|
||||
install -d "$(dirname "$local_path")"
|
||||
curl -Ls "$raw_url/$remote_path" -o "$local_path"
|
||||
}
|
||||
|
||||
#----------------------------
|
||||
#--------------------------------
|
||||
# Download _custom.sh if missing
|
||||
#----------------------------
|
||||
#--------------------------------
|
||||
function ifexists_custom() {
|
||||
_urls
|
||||
local custom_path="$HOME/.hyperterm/_custom.sh"
|
||||
local custom_path="$HYPERTERM_DIR/_custom.sh"
|
||||
if [ ! -e "$custom_path" ]; then
|
||||
download_file "hyperterm/_custom.sh" "$custom_path"
|
||||
fi
|
||||
}
|
||||
|
||||
#----------------------------
|
||||
#-------------------
|
||||
# Show progress bar
|
||||
#----------------------------
|
||||
#-------------------
|
||||
function show_progress() {
|
||||
case $1 in
|
||||
1) printf '%s\r' "##### (33%)" ;;
|
||||
2) printf '%s\r' "############# (66%)" ;;
|
||||
3) printf '%s\n' "####################### (100%) done!" ;;
|
||||
esac
|
||||
local current=$1
|
||||
local total=$2
|
||||
local message=${3:-"Procesando"}
|
||||
|
||||
if [[ $total -eq 0 ]]; then
|
||||
printf '\r%s... ' "$message"
|
||||
return
|
||||
fi
|
||||
|
||||
local percentage=$((current * 100 / total))
|
||||
local filled=$((percentage / 5)) # 20 chars max
|
||||
local empty=$((20 - filled))
|
||||
|
||||
# Truncate long filenames for better display
|
||||
local display_message="$message"
|
||||
if [[ ${#message} -gt 30 ]]; then
|
||||
display_message="...${message: -27}"
|
||||
fi
|
||||
|
||||
# Clear the line first, then show progress
|
||||
printf '\r\033[K[%*s%*s] %d%% (%d/%d) %s' \
|
||||
"$filled" "$(printf '#%.0s' $(seq 1 $filled))" \
|
||||
"$empty" "" \
|
||||
"$percentage" "$current" "$total" "$display_message"
|
||||
|
||||
[[ $current -eq $total ]] && printf '\n'
|
||||
}
|
||||
|
||||
#----------------------------
|
||||
#------------------------------
|
||||
# Update HyperTerm environment
|
||||
#----------------------------
|
||||
#------------------------------
|
||||
function updbashrc() {
|
||||
_urls
|
||||
local repo_info
|
||||
repo_info=$(_get_repo_urls) || return 1
|
||||
|
||||
# Step 1: Download checksum and _custom.sh
|
||||
download_file "hyperterm/hyperterm.sha512" "$HOME/.hyperterm/hyperterm.sha512"
|
||||
download_file "hyperterm/hyperterm.sha512" "$HYPERTERM_DIR/hyperterm.sha512"
|
||||
ifexists_custom
|
||||
|
||||
# Step 2: Verify checksum
|
||||
(cd "$HOME/.hyperterm/" && sha512sum -c hyperterm.sha512 &> /dev/null)
|
||||
(cd "$HYPERTERM_DIR" && sha512sum -c hyperterm.sha512 &> /dev/null)
|
||||
local _integer=$?
|
||||
|
||||
if [[ "$_integer" -eq 0 ]]; then
|
||||
@@ -99,21 +128,47 @@ function updbashrc() {
|
||||
"Get your copy at: https://c.fridu.us/software/hyperterm.git"
|
||||
printf '%b\n' "$RESET"
|
||||
else
|
||||
msg "Fallo de checksum. Re-descargando archivos desde: $URL" \
|
||||
"Checksum failed. Re-downloading files from: $URL"
|
||||
show_progress 1
|
||||
sleep 1
|
||||
msg "Verificando archivos modificados..." \
|
||||
"Checking for modified files..."
|
||||
|
||||
# Step 3: Download all files from hyperterm.sha512 like list
|
||||
# Step 3: Check each file individually and download only if needed
|
||||
local files_to_update=()
|
||||
local current_file=0
|
||||
|
||||
# First pass: identify files that need updating
|
||||
while IFS= read -r line; do
|
||||
file=$(echo "$line" | cut -d' ' -f2)
|
||||
file=${file#./}
|
||||
download_file "hyperterm/$file" "$HOME/.hyperterm/$file"
|
||||
done < "$HOME/.hyperterm/hyperterm.sha512"
|
||||
show_progress 2
|
||||
sleep 1
|
||||
local expected_hash file_path
|
||||
expected_hash=$(echo "$line" | cut -d' ' -f1)
|
||||
file_path=$(echo "$line" | cut -d' ' -f2)
|
||||
file_path=${file_path#./}
|
||||
local full_path="$HYPERTERM_DIR/$file_path"
|
||||
|
||||
show_progress 3
|
||||
# Check if file exists and has correct hash
|
||||
if [[ ! -f "$full_path" ]] || ! echo "$expected_hash ./$file_path" | (cd "$HYPERTERM_DIR" && sha512sum -c --quiet >/dev/null 2>&1); then
|
||||
files_to_update+=("$file_path")
|
||||
fi
|
||||
done < "$HYPERTERM_DIR/hyperterm.sha512"
|
||||
|
||||
local total_updates=${#files_to_update[@]}
|
||||
|
||||
if [[ $total_updates -eq 0 ]]; then
|
||||
msg "✔️ Todos los archivos están actualizados" \
|
||||
"✔️ All files are up to date"
|
||||
else
|
||||
msg "Descargando $total_updates archivo(s) modificado(s)..." \
|
||||
"Downloading $total_updates modified file(s)..."
|
||||
|
||||
# Second pass: download only the files that need updating
|
||||
for file_path in "${files_to_update[@]}"; do
|
||||
((current_file++))
|
||||
if [[ "${LANG:-}" =~ ^es ]]; then
|
||||
show_progress "$current_file" "$total_updates" "Actualizando $file_path"
|
||||
else
|
||||
show_progress "$current_file" "$total_updates" "Updating $file_path"
|
||||
fi
|
||||
download_file "hyperterm/$file_path" "$HYPERTERM_DIR/$file_path"
|
||||
done
|
||||
fi
|
||||
_colors_bash "$@"
|
||||
source "$HOME/.bashrc"
|
||||
fi
|
||||
@@ -123,15 +178,15 @@ function updbashrc() {
|
||||
# Overwrite _custom.sh interactively
|
||||
#------------------------------------
|
||||
function updbashrc_custom() {
|
||||
_urls
|
||||
if [ "$(_url_exists "$URL")" -eq 200 ]; then
|
||||
_get_repo_urls > /dev/null || return 1
|
||||
|
||||
while true; do
|
||||
question=$(msg "¿Estás seguro de sobre-escribir _custom.sh? [s/N]: " \
|
||||
"Are you sure to overwrite _custom.sh? [y/N]: ")
|
||||
read -r -p "$question" input
|
||||
case "$input" in
|
||||
[yY]|[sS])
|
||||
download_file "hyperterm/_custom.sh" "$HOME/.hyperterm/_custom.sh"
|
||||
download_file "hyperterm/_custom.sh" "$HYPERTERM_DIR/_custom.sh"
|
||||
source "$HOME/.bashrc"
|
||||
break ;;
|
||||
[nN]|"") break ;;
|
||||
@@ -139,9 +194,4 @@ function updbashrc_custom() {
|
||||
"Please answer yes or no." ;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
msg_err "El repositorio no está disponible o no hay conexión a Internet." \
|
||||
"The repository is unavailable or there's no internet connection."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
cdfe049ec07f02a1893cda29c13085d06709e09a30b0c2e1111585278315f03139d61080c883cb3fd87f2bf64e05d9b5e5eaaad84c97ced890d83c73eb399fcb ../.bash_profile
|
||||
f363606f41a2c2c8f1cc44110c64fe23b1c8feb4c788ee006222db0f5c7a3adeac2b0948626b313adc985e9b8d303a0b9ce1c5ba42746810accb54efddcd4b84 ./hyperterm.sh
|
||||
b760a908a3f6222b974abc1f7464bde0f5427f120f1e7ef1c6d97ae61769e552ef3b5cb88e193e955da72a592f07eadb812413dd50a691cd3dbb33e3da581ea6 ./core/update.sh
|
||||
5cd7bb68cbdd969b72a9355471927955696d15ac223d08468528bff103d8525339c16b374edf4d71aeb76e1776bad86727a15bc1bf684adba5d40465ad82894b ./core/update.sh
|
||||
1cfba599047d84a17ff92b695ebf527a505a30acc9ec21a2b9f410a7ea6dde4b23b5cf62e557d82f2fe9a8980649942424b879ca53baae4d4cb3057681baa7b6 ./core/colors.sh
|
||||
94e0007161652c6e9c2f1042f340f2890a66acf5123212b86eed2702c5ef5d80ab079444212d4bf1f03fbc26debe4b2fe2f0973153fb66da46606f5637f2910f ./core/git.sh
|
||||
c5ae12ee08361d1264fde5c73868fd0a80fd8810ac4e614cc333335679ad68d629d9bb88a04d27a8002d62f454105f1168df9ea63c7300c9272380b6d5311278 ./core/git.sh
|
||||
f3e00b2aa8ab9f3ab44570adaa2520408ed66fd00f551654d60b64a4be3546ec781b7efa39bcd774937e654b6ffb4c7af3f21eeb36caf9c01f82f85cf28e2b4d ./core/languages.sh
|
||||
b205de01644af11ef1dc96230e4bf12087482e26b7c0472fb6a153bf94662e4dfc01b2da0c3ca0da4af93bce05faf0e33be5422fbee85e6b69ca1cccbe194cff ./core/autodep.sh
|
||||
7447d3e167ab207d3ef4218e201a06bf5a3fc23281639f16f7f405f1d66b73923845d450fdb0a94672757866a9da0324f728564a1b61b2ed1678fe576eb565cf ./core/autocomplete.sh
|
||||
|
||||
40
install.sh
40
install.sh
@@ -36,6 +36,21 @@ function get_os_id() {
|
||||
grep "^id=" | head -n1 | cut -d= -f2 | tr -d '"'
|
||||
}
|
||||
|
||||
# -------------------------
|
||||
# Detect Git Bash/Windows
|
||||
# -------------------------
|
||||
function is_git_bash_windows() {
|
||||
# Check if running in Git Bash on Windows
|
||||
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ -n "$MSYSTEM" ]]; then
|
||||
return 0 # true
|
||||
fi
|
||||
# Additional check for Windows environment
|
||||
if [[ -n "$WINDIR" ]] || [[ -n "$SYSTEMROOT" ]]; then
|
||||
return 0 # true
|
||||
fi
|
||||
return 1 # false
|
||||
}
|
||||
|
||||
# -------------------------
|
||||
# Map programs to packages
|
||||
# -------------------------
|
||||
@@ -108,6 +123,31 @@ function install_package() {
|
||||
# Check and install programs
|
||||
# ---------------------------
|
||||
function check_and_install_programs() {
|
||||
# Skip package installation if running in Git Bash on Windows
|
||||
if is_git_bash_windows; then
|
||||
msg "Detectado Git Bash en Windows - omitiendo instalación de paquetes del sistema" \
|
||||
"Detected Git Bash on Windows - skipping system package installation"
|
||||
|
||||
# Check if essential programs are available
|
||||
local missing_programs=()
|
||||
local programs=("curl" "unzip")
|
||||
|
||||
for prog in "${programs[@]}"; do
|
||||
if ! command -v "$prog" &>/dev/null; then
|
||||
missing_programs+=("$prog")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#missing_programs[@]} -gt 0 ]]; then
|
||||
msg_err "Programas requeridos no encontrados: ${missing_programs[*]}" \
|
||||
"Required programs not found: ${missing_programs[*]}"
|
||||
msg_err "Por favor instala Git for Windows completo que incluye estos programas." \
|
||||
"Please install complete Git for Windows which includes these programs."
|
||||
exit 1
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
local os_id
|
||||
os_id=$(get_os_id)
|
||||
local programs=("curl" "less" "ls" "iproute2" "unzip")
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Test spacing for diverged state
|
||||
Reference in New Issue
Block a user