| 1 |
# Check for bash |
| 2 |
[ -z "$BASH_VERSION" ] && return |
| 3 |
|
| 4 |
__dahdi_span_assignments() { |
| 5 |
local cur prev has_cmd i |
| 6 |
COMPREPLY=() |
| 7 |
cur=${COMP_WORDS[COMP_CWORD]} |
| 8 |
prev=${COMP_WORDS[COMP_CWORD-1]} |
| 9 |
|
| 10 |
has_cmd=0 |
| 11 |
for (( i=0; i < COMP_CWORD; i++)); do |
| 12 |
case "${COMP_WORDS[$i]}" in |
| 13 |
add | auto | dumpconfig | list | remove) |
| 14 |
has_cmd=1 |
| 15 |
break |
| 16 |
;; |
| 17 |
esac |
| 18 |
done |
| 19 |
case "$prev" in |
| 20 |
-k | --key) COMPREPLY=( $(compgen -W 'devpath hwid location' -- $cur) ) ;; |
| 21 |
*) |
| 22 |
case "$cur" in |
| 23 |
-*) COMPREPLY=( ${COMPREPLY[@]} $(compgen -W \ |
| 24 |
'-h -k -n -v --help --key --dry-run --verbose' -- $cur ) ) |
| 25 |
;; |
| 26 |
*) |
| 27 |
if [ "$has_cmd" = 1 ]; then |
| 28 |
COMPREPLY=( ${COMPREPLY[@]} $(shopt -s nullglob; \ |
| 29 |
echo /sys/bus/dahdi_devices/devices/* ) ) |
| 30 |
else |
| 31 |
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W \ |
| 32 |
'add auto dumpconfig list remove' -- $cur) ) |
| 33 |
fi |
| 34 |
;; |
| 35 |
esac |
| 36 |
;; |
| 37 |
esac |
| 38 |
} |
| 39 |
|
| 40 |
complete -F __dahdi_span_assignments dahdi_span_assignments |
| 41 |
|
| 42 |
__dahdi_span_types() { |
| 43 |
local cur prev has_cmd i |
| 44 |
COMPREPLY=() |
| 45 |
cur=${COMP_WORDS[COMP_CWORD]} |
| 46 |
prev=${COMP_WORDS[COMP_CWORD-1]} |
| 47 |
|
| 48 |
has_cmd=0 |
| 49 |
for (( i=0; i < COMP_CWORD; i++)); do |
| 50 |
case "${COMP_WORDS[$i]}" in |
| 51 |
dumpconfig | list | set | compare) |
| 52 |
has_cmd=1 |
| 53 |
break |
| 54 |
;; |
| 55 |
esac |
| 56 |
done |
| 57 |
case "$prev" in |
| 58 |
-k | --key) COMPREPLY=( $(compgen -W 'devpath hwid location' -- $cur) ) ;; |
| 59 |
--line-type) COMPREPLY=( $(compgen -W 'E1 J1 T1' -- $cur) ) ;; |
| 60 |
*) |
| 61 |
case "$cur" in |
| 62 |
-*) COMPREPLY=( ${COMPREPLY[@]} $(compgen -W \ |
| 63 |
'-h -k -n -v --help --key --dry-run --line-type --verbose' -- $cur ) ) |
| 64 |
;; |
| 65 |
*) |
| 66 |
if [ "$has_cmd" = 1 ]; then |
| 67 |
# FIXME: check if devices are settable? |
| 68 |
COMPREPLY=( ${COMPREPLY[@]} $( \ |
| 69 |
grep -l '[EJT]1' /sys/devices/pci0000:00/0000:00:10.4/usb1/1-1/xbus-00/*/spantype 2>/dev/null | sed -e 's|/spantype||') ) |
| 70 |
else |
| 71 |
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W \ |
| 72 |
'dumpconfig list set compare' -- $cur) ) |
| 73 |
fi |
| 74 |
;; |
| 75 |
esac |
| 76 |
;; |
| 77 |
esac |
| 78 |
} |
| 79 |
|
| 80 |
complete -F __dahdi_span_types dahdi_span_types |
| 81 |
|
| 82 |
|
| 83 |
__dahdi_genconf() { |
| 84 |
local cur |
| 85 |
COMPREPLY=() |
| 86 |
prev=${COMP_WORDS[COMP_CWORD-1]} |
| 87 |
cur=${COMP_WORDS[COMP_CWORD]} |
| 88 |
|
| 89 |
case "$prev" in |
| 90 |
--line-type) COMPREPLY=( $(compgen -W 'E1 J1 T1' -- $cur) ) ;; |
| 91 |
*) |
| 92 |
case "$cur" in |
| 93 |
-*) COMPREPLY+=( $(compgen -W '-F -v -V --freepbx --version --verbose --line-type' -- $cur ) ) ;; |
| 94 |
*) |
| 95 |
COMPREPLY+=( $(compgen -W "$( perl -e 'my $file = "\u$ARGV[0]"; |
| 96 |
# Complete module name. Translate the case of the |
| 97 |
# first letter |
| 98 |
my @pats = map {"$_/Dahdi/Config/Gen/$file*.pm"} @INC; |
| 99 |
foreach (@pats) { |
| 100 |
foreach(glob) { |
| 101 |
s|.*/||; |
| 102 |
s|.pm$||; |
| 103 |
s|^(.)|lc($1)|e; |
| 104 |
print "$_ " |
| 105 |
} |
| 106 |
}')" -- $cur ) ) |
| 107 |
;; |
| 108 |
esac |
| 109 |
;; |
| 110 |
esac |
| 111 |
} |
| 112 |
|
| 113 |
complete -F __dahdi_genconf dahdi_genconf |
| 114 |
|
| 115 |
__dahdi_cfg() { |
| 116 |
local cur prev |
| 117 |
COMPREPLY=() |
| 118 |
cur=${COMP_WORDS[COMP_CWORD]} |
| 119 |
prev=${COMP_WORDS[COMP_CWORD-1]} |
| 120 |
|
| 121 |
case "$prev" in |
| 122 |
-c) COMPREPLY=( $(compgen -f -- $cur) ) ;; |
| 123 |
-S) COMPREPLY=( $(ls -d /sys/bus/dahdi_spans/devices/* 2>/dev/null | sed -e 's/.*-//') ) ;; |
| 124 |
# FIXME: A similar completion for -C (<chan1>-<chan2>) |
| 125 |
*) |
| 126 |
COMPREPLY=( ${COMPREPLY[@]} $(compgen -W \ |
| 127 |
'-c -C -f -h -s -S -t -v ' -- $cur ) ) |
| 128 |
;; |
| 129 |
esac |
| 130 |
} |
| 131 |
|
| 132 |
# Disable until -c works properly |
| 133 |
#complete -F __dahdi_cfg dahdi_cfg |