#compdef _minet minet #autoload _minet () { local cmd if (( CURRENT > 2)); then cmd=${words[2]} # Set the context for the subcommand. curcontext="${curcontext%:*:*}:pass-$cmd" # Narrow the range of words we are looking at to exclude `pass' (( CURRENT-- )) shift words # Run the completion for the subcommand case "${cmd}" in start) if (( CURRENT == 2 )); then _minet_complete_entries fi ;; esac else local -a subcommands subcommands=( "start:Connect to network" "stop:Disconnect from network" "restart:Reconnect to network" "suspend:Suspend current connection" "resume:Resume suspended connection" "status:Print connection status" ) _describe -t commands 'minet' subcommands fi } _minet_complete_entries () { local IFS=$'\n' local prefix="/usr/local/lib/minet" _values -C 'connections' ${$(find -L "$prefix" \( -name minet_helpers.sh -o -name template \) -prune -o -type f -executable -print 2>/dev/null | sed -e "s#${prefix}/\{0,1\}##" | sort):-""} }