Last active
July 28, 2025 19:22
-
-
Save aaronedev/db8751b509463f975115d66d8527c001 to your computer and use it in GitHub Desktop.
remove arch packages with fzf + show size in fzf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # db8751b509463f975115d66d8527c001 | |
| remove_official_packages() { | |
| comm -23 <(yay -Qeq | sort) <(yay -Qmq | sort) | while read pkg; do | |
| size=$(yay -Qi "$pkg" | grep "Installed Size" | awk '{print $4 $5}') | |
| # Convert size to KB for comparison (using bash arithmetic) | |
| size_kb=0 | |
| if [[ $size =~ ([0-9.]+)KiB ]]; then | |
| size_kb=${BASH_REMATCH[1]%.*} # remove decimal part | |
| elif [[ $size =~ ([0-9.]+)MiB ]]; then | |
| size_kb=$((${BASH_REMATCH[1]%.*} * 1024)) | |
| elif [[ $size =~ ([0-9.]+)GiB ]]; then | |
| size_kb=$((${BASH_REMATCH[1]%.*} * 1024 * 1024)) | |
| fi | |
| # Color based on size (>100MB = red, >10MB = yellow, else gray) | |
| if [[ $size_kb -gt 102400 ]]; then # 100MB in KB | |
| color="\033[91m" # bright red | |
| elif [[ $size_kb -gt 10240 ]]; then # 10MB in KB | |
| color="\033[93m" # yellow | |
| else | |
| color="\033[90m" # dark gray | |
| fi | |
| printf "${color}%-60s %12s\033[0m\n" "$pkg" "$size" | |
| done | fzf -q "$1" -m --ansi \ | |
| --preview 'yay -Qi {1}' \ | |
| --header 'Official repo packages (with sizes) - Red: >100MB, Yellow: >10MB, Gray: <10MB' | | |
| awk '{print $1}' | xargs -ro yay -Rns | |
| } | |
| remove_aur_packages() { | |
| yay -Qemq | while read pkg; do | |
| size=$(yay -Qi "$pkg" | grep "Installed Size" | awk '{print $4 $5}') | |
| # Convert size to KB for comparison (using bash arithmetic) | |
| size_kb=0 | |
| if [[ $size =~ ([0-9.]+)KiB ]]; then | |
| size_kb=${BASH_REMATCH[1]%.*} # remove decimal part | |
| elif [[ $size =~ ([0-9.]+)MiB ]]; then | |
| size_kb=$((${BASH_REMATCH[1]%.*} * 1024)) | |
| elif [[ $size =~ ([0-9.]+)GiB ]]; then | |
| size_kb=$((${BASH_REMATCH[1]%.*} * 1024 * 1024)) | |
| fi | |
| # Color based on size (>100MB = red, >10MB = yellow, else gray) | |
| if [[ $size_kb -gt 102400 ]]; then # 100MB in KB | |
| color="\033[91m" # bright red | |
| elif [[ $size_kb -gt 10240 ]]; then # 10MB in KB | |
| color="\033[93m" # yellow | |
| else | |
| color="\033[90m" # dark gray | |
| fi | |
| printf "${color}%-60s %12s\033[0m\n" "$pkg" "$size" | |
| done | fzf -q "$1" -m --ansi \ | |
| --preview 'yay -Qi {1}' \ | |
| --header 'AUR packages (with sizes) - Red: >100MB, Yellow: >10MB, Gray: <10MB' | | |
| awk '{print $1}' | xargs -ro yay -Rns | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment