mirror of
https://github.com/tw93/Mole.git
synced 2026-02-08 08:34:21 +00:00
format
This commit is contained in:
@@ -48,17 +48,17 @@ readonly STAT_BSD="/usr/bin/stat"
|
||||
|
||||
get_file_size() {
|
||||
local file="$1"
|
||||
$STAT_BSD -f%z "$file" 2>/dev/null || echo 0
|
||||
$STAT_BSD -f%z "$file" 2> /dev/null || echo 0
|
||||
}
|
||||
|
||||
get_file_mtime() {
|
||||
local file="$1"
|
||||
$STAT_BSD -f%m "$file" 2>/dev/null || echo 0
|
||||
$STAT_BSD -f%m "$file" 2> /dev/null || echo 0
|
||||
}
|
||||
|
||||
get_file_owner() {
|
||||
local file="$1"
|
||||
$STAT_BSD -f%Su "$file" 2>/dev/null || echo ""
|
||||
$STAT_BSD -f%Su "$file" 2> /dev/null || echo ""
|
||||
}
|
||||
|
||||
# Security and Path Validation Functions
|
||||
@@ -672,9 +672,9 @@ update_via_homebrew() {
|
||||
local brew_tmp_file=""
|
||||
local brew_exit_file=""
|
||||
cleanup_brew_update() {
|
||||
if [[ -n "$brew_pid" ]] && kill -0 "$brew_pid" 2>/dev/null; then
|
||||
kill -TERM "$brew_pid" 2>/dev/null || true
|
||||
wait "$brew_pid" 2>/dev/null || true
|
||||
if [[ -n "$brew_pid" ]] && kill -0 "$brew_pid" 2> /dev/null; then
|
||||
kill -TERM "$brew_pid" 2> /dev/null || true
|
||||
wait "$brew_pid" 2> /dev/null || true
|
||||
fi
|
||||
[[ -n "$brew_tmp_file" ]] && rm -f "$brew_tmp_file"
|
||||
[[ -n "$brew_exit_file" ]] && rm -f "$brew_exit_file"
|
||||
@@ -696,7 +696,10 @@ update_via_homebrew() {
|
||||
# Redirect brew output to temp file to avoid interfering with spinner
|
||||
# Store exit code in a separate file to avoid wait issues with zsh
|
||||
brew_exit_file="${brew_tmp_file}.exit"
|
||||
(brew update > "$brew_tmp_file" 2>&1 </dev/null; echo $? > "$brew_exit_file") &
|
||||
(
|
||||
brew update > "$brew_tmp_file" 2>&1 < /dev/null
|
||||
echo $? > "$brew_exit_file"
|
||||
) &
|
||||
brew_pid=$!
|
||||
local elapsed=0
|
||||
|
||||
@@ -723,7 +726,7 @@ update_via_homebrew() {
|
||||
# Get brew update exit code from file instead of wait
|
||||
local brew_exit=0
|
||||
if [[ -f "$brew_exit_file" ]]; then
|
||||
brew_exit=$(cat "$brew_exit_file" 2>/dev/null || echo "0")
|
||||
brew_exit=$(cat "$brew_exit_file" 2> /dev/null || echo "0")
|
||||
fi
|
||||
rm -f "$brew_exit_file"
|
||||
|
||||
@@ -736,7 +739,7 @@ update_via_homebrew() {
|
||||
local update_output=""
|
||||
|
||||
if [[ -f "$brew_tmp_file" ]]; then
|
||||
update_output=$(cat "$brew_tmp_file" 2>/dev/null)
|
||||
update_output=$(cat "$brew_tmp_file" 2> /dev/null)
|
||||
fi
|
||||
|
||||
# Check for errors in output (brew update may return 0 even on failure)
|
||||
|
||||
@@ -220,7 +220,7 @@ opt_mail_downloads() {
|
||||
local deleted=0
|
||||
for target_path in "${mail_dirs[@]}"; do
|
||||
if [[ -d "$target_path" ]]; then
|
||||
deleted=$((deleted + $(find "$target_path" -type f -mtime +30 -delete -print 2>/dev/null | wc -l | tr -d ' ')))
|
||||
deleted=$((deleted + $(find "$target_path" -type f -mtime +30 -delete -print 2> /dev/null | wc -l | tr -d ' ')))
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -243,7 +243,7 @@ opt_saved_state_cleanup() {
|
||||
|
||||
# Only delete states older than 7 days (safer - won't lose recent work)
|
||||
local deleted=0
|
||||
deleted=$(find "$state_dir" -type d -name "*.savedState" -mtime +7 -exec rm -rf {} \; -print 2>/dev/null | wc -l | tr -d ' ')
|
||||
deleted=$(find "$state_dir" -type d -name "*.savedState" -mtime +7 -exec rm -rf {} \; -print 2> /dev/null | wc -l | tr -d ' ')
|
||||
|
||||
if [[ $deleted -gt 0 ]]; then
|
||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Removed $deleted old saved state(s)"
|
||||
|
||||
@@ -10,7 +10,7 @@ get_memory_info() {
|
||||
|
||||
# Total memory
|
||||
total_bytes=$(sysctl -n hw.memsize 2> /dev/null || echo "0")
|
||||
total_gb=$(awk "BEGIN {printf \"%.2f\", $total_bytes / (1024*1024*1024)}" 2>/dev/null || echo "0")
|
||||
total_gb=$(awk "BEGIN {printf \"%.2f\", $total_bytes / (1024*1024*1024)}" 2> /dev/null || echo "0")
|
||||
[[ -z "$total_gb" || "$total_gb" == "" ]] && total_gb="0"
|
||||
|
||||
# Used memory from vm_stat
|
||||
@@ -18,16 +18,16 @@ get_memory_info() {
|
||||
vm_output=$(vm_stat 2> /dev/null || echo "")
|
||||
page_size=4096
|
||||
|
||||
active=$(echo "$vm_output" | awk '/Pages active:/ {print $NF}' | tr -d '.' 2>/dev/null || echo "0")
|
||||
wired=$(echo "$vm_output" | awk '/Pages wired down:/ {print $NF}' | tr -d '.' 2>/dev/null || echo "0")
|
||||
compressed=$(echo "$vm_output" | awk '/Pages occupied by compressor:/ {print $NF}' | tr -d '.' 2>/dev/null || echo "0")
|
||||
active=$(echo "$vm_output" | awk '/Pages active:/ {print $NF}' | tr -d '.' 2> /dev/null || echo "0")
|
||||
wired=$(echo "$vm_output" | awk '/Pages wired down:/ {print $NF}' | tr -d '.' 2> /dev/null || echo "0")
|
||||
compressed=$(echo "$vm_output" | awk '/Pages occupied by compressor:/ {print $NF}' | tr -d '.' 2> /dev/null || echo "0")
|
||||
|
||||
active=${active:-0}
|
||||
wired=${wired:-0}
|
||||
compressed=${compressed:-0}
|
||||
|
||||
local used_bytes=$(((active + wired + compressed) * page_size))
|
||||
used_gb=$(awk "BEGIN {printf \"%.2f\", $used_bytes / (1024*1024*1024)}" 2>/dev/null || echo "0")
|
||||
used_gb=$(awk "BEGIN {printf \"%.2f\", $used_bytes / (1024*1024*1024)}" 2> /dev/null || echo "0")
|
||||
[[ -z "$used_gb" || "$used_gb" == "" ]] && used_gb="0"
|
||||
|
||||
echo "$used_gb $total_gb"
|
||||
@@ -41,16 +41,16 @@ get_disk_info() {
|
||||
df_output=$(df -k "$home" 2> /dev/null | tail -1)
|
||||
|
||||
local total_kb used_kb
|
||||
total_kb=$(echo "$df_output" | awk '{print $2}' 2>/dev/null || echo "0")
|
||||
used_kb=$(echo "$df_output" | awk '{print $3}' 2>/dev/null || echo "0")
|
||||
total_kb=$(echo "$df_output" | awk '{print $2}' 2> /dev/null || echo "0")
|
||||
used_kb=$(echo "$df_output" | awk '{print $3}' 2> /dev/null || echo "0")
|
||||
|
||||
total_kb=${total_kb:-0}
|
||||
used_kb=${used_kb:-0}
|
||||
[[ "$total_kb" == "0" ]] && total_kb=1 # Avoid division by zero
|
||||
[[ "$total_kb" == "0" ]] && total_kb=1 # Avoid division by zero
|
||||
|
||||
total_gb=$(awk "BEGIN {printf \"%.2f\", $total_kb / (1024*1024)}" 2>/dev/null || echo "0")
|
||||
used_gb=$(awk "BEGIN {printf \"%.2f\", $used_kb / (1024*1024)}" 2>/dev/null || echo "0")
|
||||
used_percent=$(awk "BEGIN {printf \"%.1f\", ($used_kb / $total_kb) * 100}" 2>/dev/null || echo "0")
|
||||
total_gb=$(awk "BEGIN {printf \"%.2f\", $total_kb / (1024*1024)}" 2> /dev/null || echo "0")
|
||||
used_gb=$(awk "BEGIN {printf \"%.2f\", $used_kb / (1024*1024)}" 2> /dev/null || echo "0")
|
||||
used_percent=$(awk "BEGIN {printf \"%.1f\", ($used_kb / $total_kb) * 100}" 2> /dev/null || echo "0")
|
||||
|
||||
[[ -z "$total_gb" || "$total_gb" == "" ]] && total_gb="0"
|
||||
[[ -z "$used_gb" || "$used_gb" == "" ]] && used_gb="0"
|
||||
@@ -64,12 +64,12 @@ get_uptime_days() {
|
||||
local boot_output boot_time uptime_days
|
||||
|
||||
boot_output=$(sysctl -n kern.boottime 2> /dev/null || echo "")
|
||||
boot_time=$(echo "$boot_output" | sed -n 's/.*sec = \([0-9]*\).*/\1/p' 2>/dev/null || echo "")
|
||||
boot_time=$(echo "$boot_output" | sed -n 's/.*sec = \([0-9]*\).*/\1/p' 2> /dev/null || echo "")
|
||||
|
||||
if [[ -n "$boot_time" && "$boot_time" =~ ^[0-9]+$ ]]; then
|
||||
local now=$(date +%s 2>/dev/null || echo "0")
|
||||
local now=$(date +%s 2> /dev/null || echo "0")
|
||||
local uptime_sec=$((now - boot_time))
|
||||
uptime_days=$(awk "BEGIN {printf \"%.1f\", $uptime_sec / 86400}" 2>/dev/null || echo "0")
|
||||
uptime_days=$(awk "BEGIN {printf \"%.1f\", $uptime_sec / 86400}" 2> /dev/null || echo "0")
|
||||
else
|
||||
uptime_days="0"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user