Skip to content

Instantly share code, notes, and snippets.

@kidpixo
Created March 3, 2026 09:10
Show Gist options
  • Select an option

  • Save kidpixo/9036b7a6e49314fe86851eab6b24c53e to your computer and use it in GitHub Desktop.

Select an option

Save kidpixo/9036b7a6e49314fe86851eab6b24c53e to your computer and use it in GitHub Desktop.
archlinux-downgrade/downgrade + yay cache + bash completion + (optional) fzf
# ------------------------------------------------------------------------------
# Function: downgrade-yay
# Description: Wraps 'downgrade' for AUR packages built via yay.
# If no argument is provided, it uses fzf to select from the cache.
# Usage: downgrade-yay <package-name>
# Dependencies: downgrade, fzf (optional for interactive selection)
# ------------------------------------------------------------------------------
downgrade-yay() {
local YAY_DIR="$HOME/.cache/yay"
local TARGET_PKG="$1"
# If no package is provided, try to use fzf to pick one
if [ -z "$TARGET_PKG" ]; then
if command -v fzf >/dev/null 2>&1; then
TARGET_PKG=$(find "$YAY_DIR" -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | fzf --header="Select package to downgrade" --height=40% --reverse)
# Exit if user canceled fzf (Esc)
[ -z "$TARGET_PKG" ] && return 0
else
echo "Error: No package name provided and fzf is not installed."
echo "Usage: downgrade-yay <package-name>"
return 1
fi
fi
local YAY_CACHE="$YAY_DIR/$TARGET_PKG"
# Final check if the chosen directory exists
if [ ! -d "$YAY_CACHE" ]; then
echo "Error: Cache directory not found at $YAY_CACHE"
return 1
fi
sudo downgrade --pacman-cache "$YAY_CACHE" "$TARGET_PKG"
}
# --- Bash Tab Completion (The fallback/Standard way) ---
_downgrade_yay_completions() {
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
local cache_dir="$HOME/.cache/yay"
if [ -d "$cache_dir" ]; then
local opts=$(find "$cache_dir" -maxdepth 1 -mindepth 1 -type d -printf '%f\n')
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
fi
return 0
}
complete -F _downgrade_yay_completions downgrade-yay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment