### Copyright (C) 1996 Per Zacho
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 2 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

proc completion {} {
    # User<->Bash interface / Completion

    Desc "This configuration page will help you to setup options relating to"\
    "commandline completion and filename globbing."

    ShortDesc "Completion"

    ### Completion options ###

    Header head1 -text "Completion options"\
	    -background gray\
	    -help "Options concerning completion of user input."

    Radio showamb -text "If words have more than one possible completion..."\
	    -defaultIndex 0\
	    -entryhelp {"ring the bell" "If word is ambiguous shell will ring the bell (beep)."\
	    "list all completions" "If word is ambiguous shell will list all possible completions"}\
	    -help "If the command is ambiguous (i.e. there are more than one possible"\
	    "way of completing the sentence), then shell either list the possible"\
	    "completions, or ring the bell."\
	    -packFrame:fill x

    Int compquery -text "Max. number of elements to show without asking"\
	    -default 100\
	    -help "You can specify how many possible completions you would like to see,"\
	    "without shell asking you for verification. This often happens, when trying to"\
	    "auto complete when seed is too general."

    CheckBox exptilde -text "Expand tilde (~) when completing"\
	    -default 0\
	    -help "If enabled Bash will expand tilde (~) to its value. This is most likely"\
	    "the path to your home directory."

    File-Dir-Browser hostfile -text "Hostname file"\
	-exist 1\
	-default "/etc/hosts"

    foreach elm {frame_hostfile hostfile com_hostfile} {
	Help $elm "When Bash is to complete hostname, you can specify where this information"\
	    "is stored. The file must have the same format as /etc/hosts."
    }

    Line line1

    Entry fignoreComponent -text "Filename suffix"\
	    -help "A sufix is the last part of the file name.\nExample: \".o\" is the"\
	    "suffix of \"file.o\" and \"~\" is the suffix of \"file~\"."

    ExtEntry fignore -text "File suffixes to ignore upon filename completion"\
	    -entries fignoreComponent\
	    -help "Here you can construct a list of filename suffixes to ignore upon file"\
	    "name completion."\
	    -packFrame:fill x

    ### Globbing options ###

    Header head2 -text "Globbing options"\
	    -background gray\
	    -help "When Bash tries to translate a filename pattern to a number of physical"\
	    "existing filenames, it is called \"globbing\". Wildcards to be used in Bash is:\n"\
	    "?\tAny single character\n*\tAny string of characters\n\[set\]\tAny character"\
	    "in set\n\[!set\]\tAny character _not_ in set"

    CheckBox noglob -text "Expand wildcards (* and ? in filenames)"\
	    -default 1\
	    -help "Wildcards is often used when handling multiple files. Expanding from"\
	    "wildcards to filenames is the job of the shell (globbing). Disabling this feature"\
	    "disallows you from using this convenience."

    CheckBox nullglob -text "Allow null-string expansion"\
	    -default 0\
	    -help "If no filenames match with the wildcard pattern, then either the pattern"\
	    "will be replaced with a null-string, or Bash will leave the pattern for the program"\
	    "to interpret."

    CheckBox dotglob -text "Include dot-files upon filename globbing"\
	    -default 0\
	    -help "Files with a prefix dot (.) is normally considered hidden--also when"\
	    "globbing filenames from pattern. With this option, you are able to pick dotfiles"\
	    "with wildcards.\nExample: Try to type \"echo *\" in your home directory with and"\
	    "without this option, and see the difference."

    PageEnd {
	if {$compquery < 0} {
	    error "This number has to be a positive number"
	}
    }

    Save {
	### Completion options ###
	if {$showamb(index) || $generateDefault} {
	    print -file inputrc "set show-all-if-ambiguous [pick $showamb(index) on off]"
	}

	if {$compquery != 100 || $generateDefault} {
	    print -file inputrc "set completion-query-items $compquery"
	}

	if {$exptilde || $generateDefault} {
	    print -file inputrc "set expand-tilde [pick $exptilde on off]"
	}

	if {$hostfile != "/etc/hosts" || $generateDefault} {
	    print "[pick {$hostfile != ""} "export HOSTFILE=$hostfile" "unset HOSTFILE"]"
	}
	
	set temp ""
	forevery fignore {
	    if {$fignoreComponent != ""} {
		append temp "$fignoreComponent:"
	    }
	}
	if {$temp != ""} {
	    print "export FIGNORE='[string trim $temp ":"]'"
	}

	### Globbing options ###
	if {$noglob != 1 || $generateDefault} {
	    print "set [pick $noglob + -]o noglob"
	}

	if {$nullglob || $generateDefault} {
	    if [set version@bash(index)] {
		print "shopt -[pick $nullglob s u] nullglob"
	    } {
		print "[pick $nullglob "export allow_null_glob_expansion=on" "unset allow_null_glob_expansion"]"
	    }
	}

	if {$dotglob || $generateDefault} {
	    if [set version@bash(index)] {
		print "shopt -[pick $dotglob s u] dotglob"
	    } {
		print "[pick $dotglob "export glob_dot_filenames=on" "unset glob_dot_filenames"]"
	    }
	}
    }
}

