You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nutch.apache.org by misc <mi...@robotgenius.net> on 2007/11/10 02:35:35 UTC

Auto complete

Hi all-

    Another improvement.  At the end of this file is a debian style bash autocomplete script, just place into /etc/bash_complete.d/ with filename nutch, and you can tab complete at the command prompt, ie

bash> nutch [tab][tab]

    crawl readdb convdb mergedb readlinkdb inject generate freegen fetch fetch2 parse 
    readseg mergesegs updatedb invertlinks mergelinkdb index merge dedup plugin server

bash> nutch c[tab][tab]

    crawl convdb

etc.

    This also includes optional parameters, and filename completion where it can be used.  I really like having this when typing in long nutch commands.

    I guess I should open a Jira trouble ticket also for this, probably Monday when I have more time.

    The file is heavily taken from the corresponding svn file that does the same thing.

                        -Jim

File begins here:



shopt -s extglob

_nutch()
{
        local cur cmds cmdOpts optsParam opt
        local i

        COMPREPLY=()
        cur=${COMP_WORDS[COMP_CWORD]}

        # Possible expansions
        cmds='crawl readdb convdb mergedb readlinkdb inject generate freegen fetch fetch2 parse readseg mergesegs updatedb invertlinks \
mergelinkdb index merge dedup plugin server'

        if [[ $COMP_CWORD -eq 1 ]] ; then
                COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
                return 0
        fi

        # options that require a parameter
        # This needs to be filled in better
        optsParam="-topN|-depth"


        # if not typing an option, or if the previous option required a
        # parameter, then fallback on ordinary filename expansion
        if [[ "$cur" != -* ]] || \
           [[ ${COMP_WORDS[COMP_CWORD-1]} == @($optsParam) ]] ; then
                return 0
        fi

        # possible options for the command
        cmdOpts=
        case ${COMP_WORDS[1]} in
        crawl)
                cmdOpts="-dir -threads -depth -topN"
                ;;
        readdb)
                cmdOpts="-stats -dump -topN -url"
                ;;
        convdb)
                cmdOpts="-withMetadata"
                ;;
        mergedb)
                cmdOpts="-normalize -filter"
                ;;
        readlinkdb)
                cmdOpts="-dump -url"
                ;;
        inject)
                cmdOpts=""
                ;;
        generate)
                cmdOpts="-force -topN -numFetchers -adddays -noFilter"
                ;;
        freegen)
                cmdOpts="-filter -normalize"
                ;;
        fetch)
                cmdOpts="-threads -noParsing"
                ;;
        fetch2)
                cmdOpts="-threads -noParsing"
                ;;
        parse)
                cmdOpts=""
                ;;
        readseg)
                cmdOpts="-dump -list -get -nocontent -nofetch -nogenerate -noparse -noparsedata -noparsetext -dir"
                ;;
        mergesegs)
                cmdOpts="-dir -filter -slice"
                ;;
        updatedb)
                cmdOpts="-dir -force -normalize -filter -noAdditions"
                ;;
        invertlinks)
                cmdOpts="-dir -force -noNormalize -noFilter"
                ;;
        mergelinkdb)
                cmdOpts="-normalize -filter"
                ;;
        index)
                cmdOpts=""
                ;;
        merge)
                cmdOpts="-workingdir"
                ;;
        dedup)
                cmdOpts=""
                ;;
        plugin)
                cmdOpts=""
                ;;
        server)
                cmdOpts=""
                ;;
        *)
                ;;
        esac

        # take out options already given
        for (( i=2; i<=$COMP_CWORD-1; ++i )) ; do
                opt=${COMP_WORDS[$i]}

                cmdOpts=" $cmdOpts "
                cmdOpts=${cmdOpts/ ${opt} / }

                # skip next option if this one requires a parameter
                if [[ $opt == @($optsParam) ]] ; then
                        ((++i))
                fi
        done

        COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )

        return 0
}
complete -F _nutch -o default nutch