#!/bin/sh -e
#
# fapt - query the apt cache

selected_package=$(apt-cache search "${1:-.}" | fzf --ignore-case --exact --ansi)

# Check if a package is selected
if [ -n "${selected_package}" ]; then
  # Extract package name from the selected line
  package_name=$(echo "${selected_package}" | awk '{ print $1 }')

  # Copy installation command to the clipboard
  install_command="sudo apt install ${package_name}"
  echo "${install_command}" | wl-copy

  # Display package information
  apt-cache show "${package_name}" | less
else
  echo "No package selected."
fi
