#!/bin/sh -e
#
# apt-list-manually - show a list of apt packages a user manually installed

info() { printf "%b$1%b %s\n" "$2" >&2; }

info "list of manually installed apt packages. (/var/log/apt/history.log)"

apt_list=$(apt list --installed)

grep "install" </var/log/apt/history.log \
  | sed -E -e "s/^.*apt(-get)?(\s--?\S+)*\sinstall(\s--?\S+)*\s//" \
  | sed -E -e "s/(^|\s)--?\S+//g" -e "s/(\S)\s+(\S)/\1\n\2/g" \
  | sort | uniq \
  | xargs -I {} sh -c "echo \"${apt_list}\" | grep -e '{}/'" \
  | column -t -s " " | sed -E -e "s/^/  /g"
