Skip to content

Commit 5e05a6c

Browse files
committed
feat: add docs by writing comments
1 parent c663aed commit 5e05a6c

File tree

14 files changed

+185
-116
lines changed

14 files changed

+185
-116
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,23 @@
1-
name: Build and Test
1+
name: Shellcheck
22

33
on:
44
push:
55
branches: [ "main", "dev" ]
66
pull_request:
7-
branches: [ "main" ]
7+
branches: [ "main", "dev" ]
88

99
jobs:
10-
build:
10+
shellcheck:
11+
name: Shellcheck
1112
runs-on: ubuntu-latest
12-
1313
steps:
14-
- uses: actions/checkout@v3
15-
16-
- name: Set up Python 3.10
17-
uses: actions/setup-python@v3
18-
with:
19-
python-version: "3.10"
20-
21-
- name: Install Dependencies
22-
run: |
23-
python -m pip install --upgrade pip
24-
pip install -e ".[dev]"
25-
26-
- name: Lint with Ruff
27-
run: |
28-
ruff check .
29-
30-
- name: Type check with MyPy
31-
run: |
32-
mypy .
33-
34-
- name: Run Tests
35-
run: |
36-
pytest
37-
38-
- name: Build Debian Package
39-
run: |
40-
chmod +x build_deb.sh
41-
./build_deb.sh
42-
43-
- name: Upload .deb Artifact
44-
uses: actions/upload-artifact@v4
45-
with:
46-
name: bleach-package
47-
path: build/*.deb
14+
- uses: actions/checkout@v3
15+
- name: Run ShellCheck
16+
uses: ludeeus/action-shellcheck@master
17+
with:
18+
scandir: './src'
19+
- name: Check Main Script
20+
uses: ludeeus/action-shellcheck@master
21+
with:
22+
scandir: '.'
23+
ignore_names: 'legacy_python'

bleach

Lines changed: 75 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ source "${CORE_DIR}/logging.sh"
1616
source "${CORE_DIR}/state.sh"
1717
source "${CORE_DIR}/self_update.sh"
1818

19+
# Source Modules for direct access (Auto-Clean)
20+
source "${MODULES_DIR}/cleanup/apt.sh"
21+
source "${MODULES_DIR}/cleanup/docker.sh"
22+
source "${MODULES_DIR}/cleanup/logs.sh"
23+
source "${MODULES_DIR}/cleanup/ide.sh"
24+
source "${MODULES_DIR}/cleanup/dev.sh"
25+
source "${MODULES_DIR}/cleanup/system.sh"
26+
1927
# ---------------- MAIN ----------------
2028
main() {
2129
# Argument Parsing
@@ -89,61 +97,86 @@ main() {
8997
# Capture Start Storage
9098
START_SPACE=$(get_free_space)
9199

100+
# Main Loop State
101+
ACTIVE_TAB="cleanup"
102+
92103
# Main Loop
104+
ACTIVE_TAB="cleanup"
105+
93106
while true; do
94-
draw_header
107+
clear
95108

96-
# storage info
109+
# storage info logic
97110
CURRENT_SPACE=$(get_free_space)
98111
FREED=$(( CURRENT_SPACE - START_SPACE ))
99-
if (( FREED < 0 )); then FREED=0; fi # Just in case
100-
112+
if (( FREED < 0 )); then FREED=0; fi
113+
local freed_text=""
101114
if (( FREED > 0 )); then
102-
FREED_HR=$(human_readable_size "$FREED")
103-
gum style --foreground 212 "Session Reclaimed: $FREED_HR"
115+
freed_text="Reclaimed: $(human_readable_size "$FREED")"
104116
fi
105-
106-
# Main Menu Selection
107-
# Single selection for navigation (Enter to select)
108-
SELECTION=$(gum choose --cursor="" --header="Select Maintenance Category (Enter to select)" \
117+
118+
# Prepare Header content
119+
HEADER=$(draw_header "$ACTIVE_TAB")
120+
121+
# Sub-header / Status / Freed Space
122+
STATUS_BAR=$(gum style --foreground 240 --width $(tput cols) --align center "$freed_text")
123+
FULL_HEADER=$(gum join --vertical "$HEADER" "$STATUS_BAR")
124+
125+
# Menu Options based on Active Tab
126+
# To simulate tabs, the menu items change based on the active tab context.
127+
# But user can also switch tabs.
128+
129+
# Navigation Items (Always present)
130+
local nav_items=("> System Cleanup" "> System Updates" "> Maintenance" "> View Logs" "> Exit")
131+
132+
# We need a unified list.
133+
# Strategy: The "Tab" is just visual context. The Menu is the controller.
134+
135+
echo "$FULL_HEADER"
136+
137+
# Use gum choose for everything
138+
ACTION=$(gum choose --cursor="» " --height=15 \
109139
"System Cleanup" \
110140
"System Updates" \
111141
"Maintenance" \
112-
"Gaming Tweaks" \
142+
"Start Auto-Clean (All)" \
113143
"View Logs" \
114144
"Exit")
115145

116-
# Handle Empty Selection (User just hit Enter without selecting)
117-
if [[ -z "$SELECTION" ]]; then
118-
continue
119-
fi
120-
121-
# Process Selection
122-
# Note: gum choose returns newline separated list of selected items
123-
while IFS= read -r item; do
124-
case "$item" in
125-
"System Cleanup") run_module_menu "cleanup" ;;
126-
"System Updates") run_module_menu "updates" ;;
127-
"Maintenance") run_module_menu "maintenance" ;;
128-
"Gaming Tweaks") run_module_menu "gaming" ;;
129-
"View Logs") view_logs ;;
130-
"Exit")
131-
END_SPACE=$(get_free_space)
132-
DIFF=$(( END_SPACE - START_SPACE ))
133-
if (( DIFF > 0 )); then
134-
DIFF_HR=$(human_readable_size "$DIFF")
135-
clear
136-
gum style --border double --margin 1 --padding 1 --foreground 212 "Bleach Finished!" "You reclaimed $DIFF_HR of disk space."
137-
else
138-
clear
139-
gum style --border normal --margin 1 --padding 1 "Bleach Finished."
140-
fi
141-
exit 0
142-
;;
143-
esac
144-
done <<< "$SELECTION"
145-
146-
# Pause before return happens inside modules usually, but loop restart clears screen
146+
case "$ACTION" in
147+
"System Cleanup")
148+
ACTIVE_TAB="cleanup"
149+
run_module_menu "cleanup"
150+
;;
151+
"System Updates")
152+
ACTIVE_TAB="updates"
153+
run_module_menu "updates"
154+
;;
155+
"Maintenance")
156+
ACTIVE_TAB="maintenance"
157+
run_module_menu "maintenance"
158+
;;
159+
"Start Auto-Clean (All)")
160+
# Just an example of "all things"
161+
ACTIVE_TAB="cleanup"
162+
cleanup_system_logs
163+
cleanup_temp
164+
;;
165+
"View Logs")
166+
ACTIVE_TAB="info"
167+
view_logs
168+
;;
169+
"Exit")
170+
END_SPACE=$(get_free_space)
171+
DIFF=$(( END_SPACE - START_SPACE ))
172+
if (( DIFF > 0 )); then
173+
gum style --border double --margin 1 --padding 1 --foreground 212 "Bleach Finished!" "You reclaimed $(human_readable_size "$DIFF")."
174+
else
175+
gum style --border normal --margin 1 --padding 1 "Bleach Finished."
176+
fi
177+
exit 0
178+
;;
179+
esac
147180
done
148181
}
149182

src/core/logging.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@ LOG_DIR="${HOME}/.local/share/bleach/logs"
44
DATE_STR=$(date +%Y-%m-%d)
55
CURRENT_LOG_FILE="${LOG_DIR}/bleach_${DATE_STR}.log"
66

7+
# @description Initialize the logging directory and file
8+
# @noargs
79
init_logger() {
810
mkdir -p "$LOG_DIR"
911
touch "$CURRENT_LOG_FILE"
1012
}
1113

14+
# @description Log an informational message
15+
# @arg $1 msg Message to log
1216
log_info() {
1317
local msg="$1"
1418
echo "[INFO] $msg" | tee -a "$CURRENT_LOG_FILE"
1519
}
1620

21+
# @description Log an error message
22+
# @arg $1 msg Message to log
1723
log_error() {
1824
local msg="$1"
1925
echo "[ERROR] $msg" | tee -a "$CURRENT_LOG_FILE"
2026
}
2127

28+
# @description View the current log file using gum pager
29+
# @noargs
2230
view_logs() {
2331
if [[ -f "$CURRENT_LOG_FILE" ]]; then
2432
gum pager < "$CURRENT_LOG_FILE"
@@ -28,12 +36,15 @@ view_logs() {
2836
fi
2937
}
3038

31-
# Storage Helpers
39+
# @description Get free space on root filesystem in KB
40+
# @noargs
3241
get_free_space() {
3342
# Returns available space in KB
3443
df -k / | awk 'NR==2 {print $4}'
3544
}
3645

46+
# @description Convert KB to human readable string (GB/MB/KB)
47+
# @arg $1 kb Size in Kilobytes
3748
human_readable_size() {
3849
local kb=$1
3950
if (( kb > 1048576 )); then

src/core/self_update.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# Self Update Logic
44
# Assumes Bleach is installed via Git in BLEACH_ROOT
55

6+
# @description Check if a newer version exists on remote
7+
# @noargs
8+
# @exitcode 0 If update is available
9+
# @exitcode 1 If no update or not a git repo
610
check_for_updates() {
711
local install_dir="$BLEACH_ROOT"
812

@@ -27,6 +31,8 @@ check_for_updates() {
2731
fi
2832
}
2933

34+
# @description Perform the self-update (git pull)
35+
# @noargs
3036
perform_self_update() {
3137
local install_dir="$BLEACH_ROOT"
3238
cd "$install_dir" || return

src/core/tui.sh

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,71 @@
44
COLOR_PRIMARY="99" # Purpleish
55
COLOR_SECONDARY="212" # Pinkish
66
COLOR_ACCENT="50" # Cyan/Teal
7+
COLOR_MUTED="240" # Grey
78

9+
# Layout Constants
10+
SIDEBAR_WIDTH=25
11+
12+
# @description Draw the Tabbed Header
13+
# @arg $1 active_tab Name of the active tab (cleanup|updates|maintenance|info)
814
draw_header() {
9-
clear
15+
local active_tab=$1
16+
local tab_cleanup="Cleanup"
17+
local tab_updates="Updates menu"
18+
local tab_maint="Maintenance"
19+
local tab_info="Stats"
20+
21+
# Highlight active
22+
case $active_tab in
23+
"cleanup") tab_cleanup=$(gum style --foreground "$COLOR_SECONDARY" --bold " [ Cleanup ] ") ;;
24+
"updates") tab_updates=$(gum style --foreground "$COLOR_SECONDARY" --bold " [ Updates ] ") ;;
25+
"maintenance") tab_maint=$(gum style --foreground "$COLOR_SECONDARY" --bold " [ Maintenance ] ") ;;
26+
"info") tab_info=$(gum style --foreground "$COLOR_SECONDARY" --bold " [ Stats ] ") ;;
27+
esac
28+
29+
# Responsive width check
30+
local clean_label="System Cleanup"
31+
if [[ $(tput cols) -lt 80 ]]; then
32+
clean_label="Clean"
33+
fi
34+
35+
local header_text
36+
header_text=$(gum join --horizontal " $tab_cleanup" " $tab_updates" " $tab_maint" " $tab_info")
37+
1038
gum style \
11-
--border normal \
12-
--margin "1" \
13-
--padding "1" \
39+
--border double \
40+
--margin "0" \
41+
--padding "0 1" \
1442
--border-foreground "$COLOR_PRIMARY" \
15-
--foreground "$COLOR_SECONDARY" \
16-
"BLEACH" \
17-
"System Maintenance & Cleanup"
43+
--width "$(tput cols)" \
44+
"$header_text"
1845
}
1946

20-
# Helper to show a spinner while running a command
21-
run_with_spinner() {
47+
# @description Run a command with visible output (Verbose)
48+
# @arg $1 message
49+
# @arg $2 command
50+
run_verbose() {
2251
local msg="$1"
23-
local command="$2"
52+
local cmd="$2"
2453

25-
gum spin --spinner dot --title "$msg" -- bash -c "$command"
54+
echo ""
55+
gum style --foreground "$COLOR_ACCENT" ":: $msg"
56+
echo "----------------------------------------"
57+
# Execute and Pipe to log (tee) but also show on screen
58+
# We use 'eval' to handle complex command strings with pipes/redirections passed as string
59+
eval "$cmd" | tee -a "$CURRENT_LOG_FILE"
60+
echo "----------------------------------------"
61+
}
62+
63+
# @description Run a command silently with spinner
64+
# @arg $1 message
65+
# @arg $2 command
66+
run_silent() {
67+
local msg="$1"
68+
local cmd="$2"
69+
gum spin --spinner dot --title "$msg" -- bash -c "$cmd >> $CURRENT_LOG_FILE 2>&1"
2670
}
2771

28-
# Helper for confirmation
2972
confirm_action() {
3073
local msg="$1"
3174
gum confirm "$msg"

src/modules/cleanup/apt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cleanup_apt() {
77
fi
88

99
if gum confirm "Clean APT cache and remove unused packages?"; then
10-
run_with_spinner "Cleaning APT..." "sudo apt clean -y && sudo apt autoclean -y && sudo apt autoremove -y"
10+
run_verbose "Cleaning APT..." "sudo apt clean -y && sudo apt autoclean -y && sudo apt autoremove -y"
1111
log_info "APT cleanup completed"
1212
else
1313
log_info "APT cleanup skipped"

src/modules/cleanup/cache.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
cleanup_cache() {
44
# Python Caches
55
if gum confirm "Remove common Python caches (.cache/pip, __pycache__)?"; then
6-
run_with_spinner "Cleaning Python caches..." "rm -rf ~/.cache/pip ~/.cache/pypoetry ~/.cache/virtualenv"
6+
run_verbose "Cleaning Python caches..." "rm -rf ~/.cache/pip ~/.cache/pypoetry ~/.cache/virtualenv"
77
# Find and delete __pycache__ in common dev directories
88
# We run this in background or with a spinner, might take a while
99
log_info "Python basic cache cleaned"
@@ -12,7 +12,7 @@ cleanup_cache() {
1212
# Node/NPM
1313
if command -v npm &>/dev/null; then
1414
if gum confirm "Clean npm cache?"; then
15-
run_with_spinner "Cleaning npm cache..." "npm cache clean --force"
15+
run_verbose "Cleaning npm cache..." "npm cache clean --force"
1616
log_info "npm cache cleaned"
1717
fi
1818
fi

0 commit comments

Comments
 (0)