source: trunk/klask.bash_completion @ 388

Last change on this file since 388 was 381, checked in by g7moreau, 6 years ago
  • Add bash completion for option --way
File size: 1.3 KB
Line 
1# bash completion for klask
2
3_klask() {
4   local cur prev
5
6   COMPREPLY=()
7   #_get_comp_words_by_ref cur prev
8   cur="${COMP_WORDS[COMP_CWORD]}"
9   prev="${COMP_WORDS[COMP_CWORD-1]}"
10
11   case $prev in
12      -f|--format)
13         COMPREPLY=($(compgen -W "txt html dot" -- "$cur"))
14         return 0
15         ;;
16      -k|--kind)
17         COMPREPLY=($(compgen -W "host mac" -- "$cur"))
18         return 0
19         ;;
20      -i|--vlan)
21         COMPREPLY=($(compgen -W "$(grep vlan-id: /etc/klask/klask.conf|awk '{print $2}'|xargs echo -n)" -- "$cur"))
22         return 0
23         ;;
24      -s|--shift)
25         COMPREPLY=($(compgen -W "1 2 3" -- "$cur"))
26         return 0
27         ;;
28      -w|--way)
29         COMPREPLY=($(compgen -W "all desc child parent" -- "$cur"))
30         return 0
31         ;;
32   esac
33
34   if [[ "$cur" == '-*' || $COMP_CWORD -gt 1 ]]
35   then
36      #COMPREPLY=($(compgen -W '-v --verbose -k --kind -f --format -d --day -i --vlan -m --modulo -s --shift' -- "$cur"))
37      COMPREPLY=($(compgen -W "$(klask  help|grep "^ klask ${COMP_WORDS[1]}" | sed -e 's/[\[]/\n/g;'|grep -- '^-'|cut -f 1 -d ']'|cut -f 1 -d ' '|sed -e 's/|/ /g;'|xargs echo -n)" -- "$cur"))
38   else
39      COMPREPLY=($(compgen -W "$($(which klask || echo /usr/sbin/klask) help|grep '^ klask'|awk '{print $2}'|xargs echo -n)" -- "$cur"))
40   fi
41
42   } && complete -F _klask klask
Note: See TracBrowser for help on using the repository browser.