PageRenderTime 76ms CodeModel.GetById 74ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion.d/m-a

http://github.com/brinkman83/bashrc
#! | 78 lines | 62 code | 16 blank | 0 comment | 0 complexity | 024cf1aaa1287981f5d339345cfcf65a MD5 | raw file
 1#-*- mode: shell-script;-*-
 2# Inputs:
 3#   $1 -- name of the command whose arguments are being completed
 4#   $2 -- word being completed
 5#   $3 -- word preceding the word being completed
 6#   $COMP_LINE  -- current command line
 7#   $COMP_PONT  -- cursor position
 8#   $COMP_WORDS -- array containing individual words in the current
 9#                  command line
10#   $COMP_CWORD -- index into ${COMP_WORDS} of the word containing the
11#                  current cursor position
12# Output:
13#   COMPREPLY array variable contains possible completions
14
15#
16# Syntax (simple:
17#   module-assistant  [options] command module [module ...]
18
19have module-assistant &&
20_module_assistant() {
21
22   local cur prev special i options commands
23
24   options='-h -v -q -n -i -o -s -f -u -k -l \
25   --help --verbose --quiet --no-rebuild --non-inter --unpack-once \
26   --apt-search --force --userdir --kernel-dir --kvers-list'
27
28   commands='update unpack get fakesource build list install auto-install prepare clean purge la li a-i'
29
30	COMPREPLY=()
31	cur=${COMP_WORDS[COMP_CWORD]}
32	prev=${COMP_WORDS[COMP_CWORD-1]}
33
34	for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
35		if [[ ${COMP_WORDS[i]} == @(update|fakesource|unpack|get|build|list|install|auto-install|clean|purge|la|list-available|li|list-installed|a-i) ]]; then
36			special=${COMP_WORDS[i]}
37		fi
38	done
39
40	if [ -n "$special" ]; then
41		case $special in
42		clean|purge)
43			COMPREPLY=( $( module-assistant -q compi $cur 2> /dev/null ) )
44			return 0
45			;;
46		*)
47			COMPREPLY=( $( module-assistant -q comp $cur 2> /dev/null ) )
48			return 0
49			;;
50
51		esac
52	fi
53
54	case "$prev" in
55	    -@(u|k|-kernel-dir|-kernel-dirs))
56 		     _filedir
57		     return 0
58		     ;;
59
60	    -@(l|-kver-list))
61		     COMPREPLY=( $( module-assistant -q compv $cur ) )
62		     return 0
63		     ;;
64	esac
65
66	if [[ "$cur" == -* ]]; then
67		COMPREPLY=( $( compgen -W "$options" -- $cur ) )
68	else
69		COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
70	fi
71
72	return 0
73
74}
75[ "$have" ] && complete -F _module_assistant $filenames module-assistant
76[ "$have" ] && complete -F _module_assistant $filenames m-a
77
78