Source
search select selfupdate setrequested space submit sync test unarchive uninstall \
# port(1) completion -*- shell-script -*-
_port()
{
local cur prev words cword
_init_completion || return
local mode count portdir cmdfile i port option PSEUDOPORTS
PSEUDOPORTS=( all current active inactive installed uninstalled
outdated obsolete requested unrequested leaves )
COMPREPLY=()
count=0
for i in ${words[@]}; do
[ $count -eq $cword ] && break
# Last parameter was a required parameter, now go back to mode selection
if [ "${words[((count))]}" == "$portdir" -a "$mode" == "portdir" ] \
|| [ "${words[((count))]}" == "$cmdfile" -a "$mode" == "cmdfile" ]; then
mode=""
fi
if [ -z "$mode" ]; then
case $i in
-D)
mode=portdir
portdir=${words[((count+1))]}
;;
-F)
mode=cmdfile
cmdfile=${words[((count+1))]}
;;
activate|archive|archivefetch|build|cat|cd|checksum|clean|configure|\
contents|deactivate|dependents|deps|destroot|diagnose|dir|distcheck|\
distfiles|dmg|dpkg|echo|ed|edit|extract|fetch|file|gohome|help|\
info|install|installed|lint|list|livecheck|load|location|log|\
logfile|mdmg|mirror|mpkg|notes|outdated|patch|pkg|platform|\
portpkg|provides|quit|rdependents|rdeps|reclaim|reload|rev-upgrade|\
search|select|selfupdate|setrequested|space|submit|sync|test|\
unarchive|uninstall|unload|unsetrequested|upgrade|url|usage|\
variants|version|work)
mode=$i
;;
esac
elif [ -z "$port" ]; then
if [[ $i != -* ]]; then
case $mode in
contents|uninstall|upgrade)
if command port -q installed -- "$i" | awk '{print $1}' | grep -qi '^'$i'$'; then
port=$i
fi
;;
select)
port=$i
;;
*)
if command port -q search --name --exact -- "$i" | grep -qi '^'$i'$'; then
port=$i
fi
;;
esac
fi
elif [ -z "$option" ]; then