1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
# (C) 2010 magicant
# Completion script for the "sort" command.
# Supports POSIX 2008, GNU coreutils 8.6, OpenBSD 4.8, NetBSD 5.0,
# SunOS 5.10, HP-UX 11i v3.
function completion/sort {
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=( #>#
"b ${long:+--ignore-leading-blanks}; ignore leading blanks in sort keys"
"C; like -c, but don't report disorders"
"c; check if the input is well-sorted"
"d ${long:+--dictionary-order}; consider blank or alphanumeric characters only"
"f ${long:+--ignore-case}; case-insensitive comparison"
"i ${long:+--ignore-nonprinting}; consider printable characters only"
"k: ${long:+--key:}; specify the sort field"
"m ${long:+--merge}; assume all input files are already sorted"
"n ${long:+--numeric-sort}; compare numeric values"
"o: ${long:+--output:}; specify the output file"
"r ${long:+--reverse}; sort in reverse order"
"t: ${long:+--field-separator:}; specify the field separator character"
"u ${long:+--unique}; make equal lines unique"
) #<#
case $type in (GNU|*BSD|SunOS|HP-UX)
OPTIONS=("$OPTIONS" #>#
"T: ${long:+--temporary-directory:}; specify the directory to put temporary files in"
) #<#
case $type in (GNU|SunOS|HP-UX)
OPTIONS=("$OPTIONS" #>#
"M ${long:+--month-sort}; compare month names"
) #<#
case $type in (GNU|SunOS)
OPTIONS=("$OPTIONS" #>#
"S: ${long:+--buffer-size:}; specify the initial buffer size in 1024 byte units"
) #<#
esac
esac
case $type in (GNU|*BSD)
OPTIONS=("$OPTIONS" #>#
"s ${long:+--stable}; stable sort"
) #<#
case $type in (GNU|OpenBSD)
OPTIONS=("$OPTIONS" #>#
"z ${long:+--zero-terminated}; use null bytes as the line separator"
) #<#
esac
case $type in (*BSD)
OPTIONS=("$OPTIONS" #>#
"R:; specify the line separator"
) #<#
esac
esac
esac
case $type in
(GNU)
OPTIONS=("$OPTIONS" #>#
"--batch-size:; specify the number of inputs to sort at once"
"--check::; check if the input is well-sorted"
"--compress-program:; specify the program to compress temporary files"
"--debug; print debugging messages"
"--files0-from:; specify a file containing null-separated filenames to read"
"g --general-numeric-sort; compare floating-point numbers"
"h --human-numeric-sort; compare numeric values followed by SI suffixes"
"--parallel:; specify the number of sort processes to run at a time"
"R --random-sort; sort in random order"
"--random-source:; specify the random seed file"
"--sort:; specify comparison type"
"V --version-sort; compare version numbers"
"--help"
"--version"
) #<#
;;
(OpenBSD)
OPTIONS=("$OPTIONS" #>#
"H; use merge sort rather than radix sort"
) #<#
;;
(NetBSD)
OPTIONS=("$OPTIONS" #>#
"S; non-stable sort"
) #<#
;;
(HP-UX)
OPTIONS=("$OPTIONS" #>#
"A; simple byte-by-byte comparison"
"z:; specify the buffer size per line"
) #<#
;;
esac
command -f completion//parseoptions ${long:+-es}
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
([RStz]|--batch-size|--buffer-size|--field-separator|--parallel)
;;
(--check) #>>#
complete -P "$PREFIX" -D "don't report disorders" quiet silent
complete -P "$PREFIX" -D "report disorders" diagnose-first
;; #<<#
(--compress-program)
WORDS=()
command -f completion//reexecute -e
;;
(k|--key)
typeset word="${TARGETWORD#"$PREFIX"}"
case $word in (*[[:alnum:]])
#>>#
complete -T -P "$TARGETWORD" -D "ignore leading blanks in sort keys" b
complete -T -P "$TARGETWORD" -D "consider blank or alphanumeric characters only" d
complete -T -P "$TARGETWORD" -D "case-insensitive comparison" f
complete -T -P "$TARGETWORD" -D "consider printable characters only" i
complete -T -P "$TARGETWORD" -D "compare numeric values" n
complete -T -P "$TARGETWORD" -D "sort in reverse order" r
#<<#
case $type in (GNU|SunOS|HP-UX) #>>#
complete -T -P "$TARGETWORD" -D "compare month names" M
esac #<<#
case $type in (GNU|SunOS|HP-UX) #>>#
complete -T -P "$TARGETWORD" -D "compare floating-point numbers" g
complete -T -P "$TARGETWORD" -D "compare numeric values followed by SI suffixes" h
complete -T -P "$TARGETWORD" -D "sort in random order" R
complete -T -P "$TARGETWORD" -D "compare version numbers" V
esac #<<#
esac
;;
(--sort) #>>#
complete -P "$PREFIX" -D "compare floating-point numbers" general-numeric
complete -P "$PREFIX" -D "compare numeric values followed by SI suffixes" human-numeric
complete -P "$PREFIX" -D "compare month names" month
complete -P "$PREFIX" -D "compare numeric values" numeric
complete -P "$PREFIX" -D "compare version numbers" version
complete -P "$PREFIX" -D "sort in random order" random
complete -P "$PREFIX" -D ""
;; #<<#
(T|--temporary-directory)
complete -P "$PREFIX" -S / -T -d
;;
(*)
complete -P "$PREFIX" -f
;;
esac
}
# vim: set ft=sh ts=8 sts=8 sw=8 et:
|