#!/bin/sh

prog=${0##*/}

if [ "$1" = "-a" ]; then
    apk list -a | awk -F' ' '{print $1}' | sed 's/-[^-]*-r[0-9]*//g' | sort | fzf --prompt "Packages: " --preview 'apk info -a {}'
elif [ "$1" = "-i" ]; then
    apk list -I | awk -F' ' '{print $1}' | sed 's/-[^-]*-r[0-9]*//g' | sort | fzf --prompt "Packages: " --preview 'apk info -a {}'
elif [ "$1" = "-m" ]; then
    fzf --prompt "Packages: " --preview 'apk info -a {}' < /etc/apk/world
else
    echo "Usage: $prog -a: list all packages
       $prog -i: list all installed packages
       $prog -m: list manually installed packages"
fi
