- echo "$__para_command_list"
-}
-
-__para_complete_table()
-{
- if test -z "$__para_table_list"; then
- __para_table_list="$(ls $HOME/.paraslash/afs_database/)"
- fi
- echo "$__para_table_list"
-}
-__para_complete_sender()
-{
- if test -z "$__para_sender_list"; then
- __para_sender_list="$($PC si | grep '^.* sender:$' | sed -e 's/ sender://')"
- fi
- echo "$__para_sender_list"
-}
-__para_complete_attribute()
-{
- if test -z "$__para_attributes_list"; then
- __para_attributes_list="$($PC lsatt)"
- fi
- echo "$__para_attributes_list"
-}
-__para_complete_playlist()
-{
- if test -z "$__para_playlist_list"; then
- __para_playlist_list="$($PC lspl)"
- fi
- echo "$__para_playlist_list"
-}
-__para_complete_mood()
-{
- if test -z "$__para_mood_list"; then
- __para_mood_list="$($PC lsmood)"
- fi
- echo "$__para_mood_list"
-}
-__para_complete_image()
-{
- if test -z "$__para_image_list"; then
- __para_image_list="$($PC lsimg)"
- fi
- echo "$__para_imagelist"
-}
-__para_complete_lyrics()
-{
- if test -z "$__para_lyrics_list"; then
- __para_lyrics_list="$($PC lslyr)"
+ # This extracts short and long options from the help output
+ local script='{
+ if ($1 ~ "-[a-zA-Z]," && $2 ~ "--[a-zA-Z]") {
+ print substr($1, 0, 2);
+ gsub("=.*", "", $2)
+ print $2
+ } else if ($1 ~ "--[a-zA-Z]") {
+ gsub("=.*", "", $1)
+ print $1
+ }
+ }'
+
+ if [[ "$cur" == -* ]]; then # option
+ # Depending on whether '--' is one of the previous words we
+ # complete either on local options, i.e. those of the program
+ # to execute, or call the program to print possible completions
+ # (to a subcommand).
+ local_opts=true
+ for ((i=0; i < $COMP_CWORD; i++)); do
+ [[ "${COMP_WORDS[$i]}" != '--' ]] && continue
+ local_opts=false
+ break
+ done
+ if [[ "$local_opts" == "true" ]]; then
+ result="-- $($prg --help | awk "$script")"
+ COMPREPLY=($(compgen -W "$result" -- $cur))
+ return
+ fi