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
|
# (C) 2010-2013 magicant
# This file contains functions that help completion of file size suffixes.
# Modifies the $PREFIX variable to include argument digits.
# If $TARGETWORD does not start with a digit, a non-zero status is returned.
function completion//prefixdigits {
typeset word="${TARGETWORD#"$PREFIX"}"
word=${word#[\'+-]}
case $word in
([[:digit:]]*)
while [ "${word#[[:digit:]]}" != "$word" ]; do
word=${word#[[:digit:]]}
done
PREFIX=${TARGETWORD%"$word"}
return 0
;;
(*)
PREFIX=${TARGETWORD%"$word"}
return 1
;;
esac
}
# Completes file size suffixes specified in arguments according to the current
# $TARGETWORD and $PREFIX.
function completion//completesizesuffix {
typeset arg
for arg do
case $arg in
(b) #>>#
complete -P "$PREFIX" -D "512 bytes" b
;; #<<#
(k) #>>#
complete -P "$PREFIX" -D "1024 bytes" k
;; #<<#
(m) #>>#
complete -P "$PREFIX" -D "1024^2 bytes" m
;; #<<#
(g) #>>#
complete -P "$PREFIX" -D "1024^3 bytes" g
;; #<<#
(KMGB) #>>#
complete -P "$PREFIX" -D "1024 bytes" K
complete -P "$PREFIX" -D "1000 bytes" KB
complete -P "$PREFIX" -D "1024^2 bytes" M
complete -P "$PREFIX" -D "1000^2 bytes" MB
complete -P "$PREFIX" -D "1024^3 bytes" G
complete -P "$PREFIX" -D "1000^3 bytes" GB
;; #<<#
(GNU*) #>>#
command -f completion//completesizesuffix KMGB
complete -P "$PREFIX" -D "1024^4 bytes" T
complete -P "$PREFIX" -D "1000^4 bytes" TB
complete -P "$PREFIX" -D "1024^5 bytes" P
complete -P "$PREFIX" -D "1000^5 bytes" PB
complete -P "$PREFIX" -D "1024^7 bytes" Z
complete -P "$PREFIX" -D "1000^7 bytes" ZB
complete -P "$PREFIX" -D "1024^8 bytes" Y
complete -P "$PREFIX" -D "1000^8 bytes" YB
#<<#
if [ "$arg" != GNU-E ]; then #>>#
complete -P "$PREFIX" -D "1024^6 bytes" E
complete -P "$PREFIX" -D "1000^6 bytes" EB
fi #<<#
;;
esac
done
return 0
}
# Completes the argument to the --block-size option of df, du, and ls commands.
function completion//completeblocksize {
if ! command -f completion//prefixdigits; then #>>#
complete -P "$PREFIX" -D "print size using K, M, etc. for 1024^n" human-readable
complete -P "$PREFIX" -D "print size using k, M, etc. for 1000^n" si
fi #<<#
command -f completion//completesizesuffix GNU
}
# vim: set ft=sh ts=8 sts=8 sw=8 noet:
|