Three steps to complete the package name using tab key in pkg_add
HOME » NOTEBOOK

1. Fetch a index.txt file from OpenBSD Mirror

$ ftp -Vo index.txt https://cdn.openbsd.org/pub/OpenBSD/$(uname -r)/packages/$(uname -p)/index.txt
index.txt    100% |**********************************************************|   763 KB    00:00
$

2. List package names only from the index.txt file

$ awk '/\.tgz$/ { print $NF }' index.txt | head -5
0ad-0.0.22p0.tgz
0ad-data-0.0.22.tgz
2048-cli-0.9.1.tgz
2bwm-0.3.tgz
AcePerl-1.92p2-opt.tgz
$

3. Make a selection of single package names to pkg_add

$ set -A complete_pkg_add $(awk '/\.tgz$/ { print $NF }' index.txt)

And now, you can complete package names with tab key as follows.

$ pkg_add postgresql
postgresql-client-10.5p1.tgz              postgresql-plpython-10.5p0.tgz
postgresql-contrib-10.5p0.tgz             postgresql-plr-8.3.0.17.tgz
postgresql-docs-10.5.tgz                  postgresql-plv8-1.4.2p6.tgz
postgresql-odbc-10.02.0000.tgz            postgresql-previous-9.6.6p0.tgz
postgresql-pg_upgrade-10.5p0.tgz          postgresql-server-10.5p4.tgz
postgresql-pllua-1.0p4.tgz                postgresql_autodoc-1.40p1.tgz
$ pkg_add postgresql-c
postgresql-client-10.5p1.tgz              postgresql-contrib-10.5p0.tgz
$ pkg_add postgresql-client-10.5p1.tgz

Reference

For details about complete_, see the manual ksh(1).

For more practical cases is in dot_ksh_completions which made by Mr. Bieber.

Special Thanks

Mr. Roman, He tought me how to use ftp command kindly!