]> git.tuebingen.mpg.de Git - gsu.git/blobdiff - subcommand
man: Make "roff" the default output mode.
[gsu.git] / subcommand
index a07f4145c69adb6fa319dbdaa9c97e3b0a2d5cde..13e3d83ab082707e3555d435999f1510e1d9d4f1 100644 (file)
@@ -187,6 +187,8 @@ _gsu_print_available_commands()
 
 # Print all options of the given optstring to stdout if the word in the current
 # command line begins with a hyphen character.
+#
+# Returns 0 if the current word does not start with a hyphen, one otherwise.
 gsu_complete_options()
 {
        local opts="$1" cword="$2" cur opt
@@ -198,13 +200,12 @@ gsu_complete_options()
        ret=0
        [[ ! "$cur" == -* ]] && return
 
-       ret=0
        for ((i=0; i < ${#opts}; i++)); do
                opt="${opts:$i:1}"
                [[ "$opt" == ":" ]] && continue
                printf "%s" "-$opt "
-               let ret++
        done
+       ret=1
 }
 
 com_prefs_options='e'
@@ -255,7 +256,7 @@ com_prefs()
                        printf "# optional"
                        ;;
                esac
-               printf "%s: %s" "$option_type" "$description"
+               printf " %s: %s" "$option_type" "$description"
                if [[ "$required" != "yes" && "$required" != "true" ]]; then
                        printf " [%s]" "$default_value"
                fi
@@ -293,7 +294,7 @@ Print the manual.
 
 Usage: man [-m <mode>] [-b <browser>]
 
--m: Set output format (text, roff or html). Default: text.
+-m: Set output format (text, roff or html). Default: roff.
 -b: Use the specified browser. Implies html mode.
 
 If stdout is not associated with a terminal device, the command
@@ -309,9 +310,6 @@ file is displayed as a page in the web browser. If -b is not given,
 the command stored in the $BROWSER environment variable is executed
 with the path to the temporary file as an argument. If $BROWSER is
 unset, elinks(1) is assumed.
-
-It is recommended to specify the output format with -m as the default
-mode might change in future versions of gsu.
 '
 
 _gsu_read_line()
@@ -522,7 +520,7 @@ com_man()
                o_m='html'
                browser="$o_b"
        elif [[ -z "$o_m" ]]; then
-               o_m='text'
+               o_m='roff'
        fi
 
        _gsu_isatty && isatty='true' || isatty='false'
@@ -738,7 +736,12 @@ com_complete()
                local -a candidates;
 
                candidates=(\$($0 complete "\$COMP_CWORD" "\${COMP_WORDS[@]}"));
-               COMPREPLY=(\$(compgen -W "\${candidates[*]}" -- "\$cur"));
+               if ((\$? == 0)); then
+                       COMPREPLY=(\$(compgen -W "\${candidates[*]}" -- "\$cur"));
+               else
+                       compopt -o filenames;
+                       COMPREPLY=(\$(compgen -fd -- "\$cur"));
+               fi
 EOF
                ret=$GSU_SUCCESS
                return
@@ -756,8 +759,9 @@ EOF
        shift
        words=("$@")
        cmd="${words[1]}"
-       ret=$GSU_SUCCESS # It's not an error if no completer was defined
-       [[ "$(type -t "complete_$cmd")" != "function" ]] && return
+       # if no completer is defined for this subcommand we exit unsuccessfully
+       # to let the generic completer above fall back to file name completion.
+       [[ "$(type -t "complete_$cmd")" != "function" ]] && exit 1
        "complete_$cmd" "$cword" "${words[@]}"
        # ignore errors, they would only clutter the completion output
        ret=$GSU_SUCCESS