​
I've always found it annoying that pacman -Rs leaves behind a bunch of folders in my home directory. I wrote this Fish function to handle the system uninstall and then automatically scan for and offer to delete leftover residue in ~/.config, ~/.local, ~/.cache, etc.
I’m looking for some feedback—is this safe enough for daily use, or is there a better way to handle home directory cleanup that I'm missing?
```fish
function purge --description 'Deep clean package residue with directory-only filters'
set -l pkg_name $argv[1]
# 1. Validation
if test -z "$pkg_name"; set_color red; echo "Error: Provide a package name."; set_color normal; return 1; end
if not pacman -Qi $pkg_name >/dev/null 2>&1; set_color red; echo "Error: '$pkg_name' not found."; set_color normal; return 1; end
# 2. Intelligence Gathering
echo "--- Phase 1: Mapping package fingerprints ---"
set -l internal_names (pacman -Ql $pkg_name | grep -E '/usr/bin/|/usr/share/applications/' | sed -E 's|.*/||' | sed 's/\.desktop//' | sort -u)
set -l clean_pkg_name (echo $pkg_name | sed -E 's/-(bin|git|lts|pkg|repo|amd64|x86_64)//g')
set -l search_terms (printf "%s\n" $pkg_name $clean_pkg_name $internal_names | sort -u)
echo "Identified search terms: $search_terms"
# 3. System Uninstall
echo "--- Phase 2: System Uninstall ---"
sudo pacman -Rs $pkg_name
# 4. Targetted Home Scanning
echo "--- Phase 3: Secure Home Scanning ---"
set -l target_dirs "$HOME/.config" "$HOME/.local/share" "$HOME/.cache" "$HOME/.local/state" "$HOME/.mozilla" "$HOME/.var/app"
for term in $search_terms
set -l term (string trim $term)
if test (string length "$term") -lt 3; continue; end
for base in $target_dirs
if not test -d "$base"; continue; end
set -l matches (find "$base" -maxdepth 2 -iname "*$term*" 2>/dev/null)
for match in $matches
if contains "$match" $target_dirs; continue; end
if test -e "$match"
set_color yellow; echo "Found residue: $match"; set_color normal
read -l -P "Delete this item? [y/N] " confirm
if test "$confirm" = "y" -o "$confirm" = "Y"
rm -rf "$match"
echo "Wiped safely."
end
end
end
end
set -l home_dot (find $HOME -maxdepth 1 -type d -name ".*$term*" 2>/dev/null)
for h_match in $home_dot
if test "$h_match" = "$HOME"; continue; end
set_color yellow; echo "Found hidden home folder: $h_match"; set_color normal
read -l -P "Delete this item? [y/N] " confirm
if test "$confirm" = "y" -o "$confirm" = "Y"; rm -rf "$h_match"; echo "Wiped."; end
end
end
set_color green; echo "Deep cleanup complete."; set_color normal
end
```
Would you guys use something like this? Any improvements welcome.