# (C) 2010 magicant

# Completion script for the "uniq" command.
# Supports POSIX 2008, GNU coreutils 8.6, FreeBSD 8.1, OpenBSD 4.8, NetBSD 5.0,
# Mac OS X 10.6.4, SunOS 5.10, HP-UX 11i v3.

function completion/uniq {

        case $("${WORDS[1]}" --version 2>/dev/null) in
                (*'coreutils'*) typeset type=GNU ;;
                (*)             typeset type="$(uname 2>/dev/null)" ;;
        esac
        case $type in
                (GNU) typeset long=true ;;
                (*)   typeset long= ;;
        esac

        typeset OPTIONS ARGOPT PREFIX
        OPTIONS=( #>#
        "c ${long:+--count}; print repeat count for each unique line"
        "d ${long:+--repeated}; print repeated lines only"
        "f: ${long:+--skip-fields:}; skip first n fields on each line in comparison"
        "s: ${long:+--skip-chars:}; skip first n characters on each line in comparison"
        "u ${long:+--unique}; don't print repeated lines"
        ) #<#

        case $type in (GNU|FreeBSD|Darwin)
                OPTIONS=("$OPTIONS" #>#
                "i ${long:+--ignore-case}; case-insensitive comparison"
                ) #<#
                case $type in (GNU)
                        OPTIONS=("$OPTIONS" #>#
                        "D; print only repeated lines in all"
                        "--all-repeated::; print only repeated lines in all"
                        "w: --check-chars:; compare at most n characters on each line"
                        "z --zero-terminated; use null bytes as the line separator"
                        "--help"
                        "--version"
                        ) #<#
                esac
        esac

        command -f completion//parseoptions
        case $ARGOPT in
        (-)
                command -f completion//completeoptions
                ;;
        (--all-repeated) #>>#
                complete -P "$PREFIX" -D "don't delimit group of repeated lines" none
                complete -P "$PREFIX" -D "print a newline before each group of repeated lines" prepend
                complete -P "$PREFIX" -D "print a newline between groups of repeated lines" separate
                ;; #<<#
        ('')
                complete -f
                ;;
        esac

}


# vim: set ft=sh ts=8 sts=8 sw=8 et:
