mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 12:06:45 +00:00
feat(purge): add --paths option to configure scan directories
- Add lib/manage/purge_paths.sh for interactive path management - Shows current paths status and opens editor for customization - Update bin/purge.sh to handle --paths option - Update README with new command
This commit is contained in:
@@ -59,6 +59,7 @@ mo clean --dry-run # Preview the cleanup plan
|
||||
mo clean --whitelist # Manage protected caches
|
||||
mo uninstall --force-rescan # Rescan applications and refresh cache
|
||||
mo optimize --whitelist # Manage protected optimization rules
|
||||
mo purge --paths # Configure project scan directories
|
||||
```
|
||||
|
||||
## Tips
|
||||
@@ -205,7 +206,7 @@ Select Categories to Clean - 18.5GB (8 selected)
|
||||
<details>
|
||||
<summary><strong>Custom Scan Paths</strong></summary>
|
||||
|
||||
Create `~/.config/mole/purge_paths` to specify custom directories (one per line, supports `~`):
|
||||
Run `mo purge --paths` to configure which directories to scan, or edit `~/.config/mole/purge_paths` directly:
|
||||
|
||||
```shell
|
||||
~/Documents/MyProjects
|
||||
@@ -213,7 +214,7 @@ Create `~/.config/mole/purge_paths` to specify custom directories (one per line,
|
||||
~/Work/ClientB
|
||||
```
|
||||
|
||||
When this file exists, only listed paths are scanned. Otherwise, defaults to `~/Projects`, `~/GitHub`, `~/dev`, etc.
|
||||
When custom paths are configured, only those directories are scanned. Otherwise, defaults to `~/Projects`, `~/GitHub`, `~/dev`, etc.
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
12
bin/purge.sh
12
bin/purge.sh
@@ -118,12 +118,9 @@ show_help() {
|
||||
echo -e "${YELLOW}Usage:${NC} mo purge [options]"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Options:${NC}"
|
||||
echo " --help Show this help message"
|
||||
echo " --paths Edit custom scan directories"
|
||||
echo " --debug Enable debug logging"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Configuration:${NC}"
|
||||
echo " To customize search paths, create: $HOME/.config/mole/purge_paths"
|
||||
echo " Add one directory path per line (supports ~)."
|
||||
echo " --help Show this help message"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Default Paths:${NC}"
|
||||
for path in "${DEFAULT_PURGE_SEARCH_PATHS[@]}"; do
|
||||
@@ -139,6 +136,11 @@ main() {
|
||||
# Parse arguments
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
"--paths")
|
||||
source "$SCRIPT_DIR/../lib/manage/purge_paths.sh"
|
||||
manage_purge_paths
|
||||
exit 0
|
||||
;;
|
||||
"--help")
|
||||
show_help
|
||||
exit 0
|
||||
|
||||
114
lib/manage/purge_paths.sh
Normal file
114
lib/manage/purge_paths.sh
Normal file
@@ -0,0 +1,114 @@
|
||||
#!/bin/bash
|
||||
# Purge paths management functionality
|
||||
# Opens config file for editing and shows current status
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Get script directory and source dependencies
|
||||
_MOLE_MANAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$_MOLE_MANAGE_DIR/../core/common.sh"
|
||||
source "$_MOLE_MANAGE_DIR/../clean/project.sh"
|
||||
|
||||
# Config file path
|
||||
readonly PURGE_PATHS_CONFIG="$HOME/.config/mole/purge_paths"
|
||||
|
||||
# Ensure config file exists with helpful template
|
||||
ensure_config_template() {
|
||||
if [[ ! -f "$PURGE_PATHS_CONFIG" ]]; then
|
||||
ensure_user_dir "$(dirname "$PURGE_PATHS_CONFIG")"
|
||||
cat > "$PURGE_PATHS_CONFIG" << 'EOF'
|
||||
# Mole Purge Paths - Directories to scan for project artifacts
|
||||
# Add one path per line (supports ~ for home directory)
|
||||
# Delete all paths or this file to use defaults
|
||||
#
|
||||
# Example:
|
||||
# ~/Documents/MyProjects
|
||||
# ~/Work/ClientA
|
||||
# ~/Work/ClientB
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
# Main management function
|
||||
manage_purge_paths() {
|
||||
ensure_config_template
|
||||
|
||||
local display_config="${PURGE_PATHS_CONFIG/#$HOME/~}"
|
||||
|
||||
# Clear screen
|
||||
if [[ -t 1 ]]; then
|
||||
printf '\033[2J\033[H'
|
||||
fi
|
||||
|
||||
echo -e "${PURPLE_BOLD}Purge Paths Configuration${NC}"
|
||||
echo ""
|
||||
|
||||
# Show current status
|
||||
echo -e "${YELLOW}Current Scan Paths:${NC}"
|
||||
|
||||
# Reload config
|
||||
load_purge_config
|
||||
|
||||
if [[ ${#PURGE_SEARCH_PATHS[@]} -gt 0 ]]; then
|
||||
for path in "${PURGE_SEARCH_PATHS[@]}"; do
|
||||
local display_path="${path/#$HOME/~}"
|
||||
if [[ -d "$path" ]]; then
|
||||
echo -e " ${GREEN}✓${NC} $display_path"
|
||||
else
|
||||
echo -e " ${GRAY}○${NC} $display_path ${GRAY}(not found)${NC}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Check if using custom config
|
||||
local custom_count=0
|
||||
if [[ -f "$PURGE_PATHS_CONFIG" ]]; then
|
||||
while IFS= read -r line; do
|
||||
line="${line#"${line%%[![:space:]]*}"}"
|
||||
line="${line%"${line##*[![:space:]]}"}"
|
||||
[[ -z "$line" || "$line" =~ ^# ]] && continue
|
||||
((custom_count++))
|
||||
done < "$PURGE_PATHS_CONFIG"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
if [[ $custom_count -gt 0 ]]; then
|
||||
echo -e "${GRAY}Using custom config with $custom_count path(s)${NC}"
|
||||
else
|
||||
echo -e "${GRAY}Using ${#DEFAULT_PURGE_SEARCH_PATHS[@]} default paths${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${YELLOW}Default Paths:${NC}"
|
||||
for path in "${DEFAULT_PURGE_SEARCH_PATHS[@]}"; do
|
||||
echo -e " ${GRAY}-${NC} ${path/#$HOME/~}"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo -e "${YELLOW}Config File:${NC} $display_config"
|
||||
echo ""
|
||||
|
||||
# Open in editor
|
||||
local editor="${EDITOR:-${VISUAL:-nano}}"
|
||||
echo -e "Opening in ${CYAN}$editor${NC}..."
|
||||
echo -e "${GRAY}Save and exit to apply changes. Leave empty to use defaults.${NC}"
|
||||
echo ""
|
||||
|
||||
# Wait for user to read
|
||||
sleep 1
|
||||
|
||||
# Open editor
|
||||
"$editor" "$PURGE_PATHS_CONFIG"
|
||||
|
||||
# Reload and show updated status
|
||||
load_purge_config
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Configuration updated"
|
||||
echo -e "${GRAY}Run 'mo purge' to clean with new paths${NC}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
manage_purge_paths
|
||||
fi
|
||||
Reference in New Issue
Block a user