1_findmnt_module()
2{
3	local cur prev OPTS
4	COMPREPLY=()
5	cur="${COMP_WORDS[COMP_CWORD]}"
6	prev="${COMP_WORDS[COMP_CWORD-1]}"
7	case $prev in
8		'-p'|'--poll')
9			COMPREPLY=( $(compgen -W "=list" -- $cur) )
10			return 0
11			;;
12		'-w'|'--timeout')
13			COMPREPLY=( $(compgen -W "timeout" -- $cur) )
14			return 0
15			;;
16		'-d'|'--direction')
17			COMPREPLY=( $(compgen -W "forward backward" -- $cur) )
18			return 0
19			;;
20		'-F'|'--tab-file')
21			local IFS=$'\n'
22			compopt -o filenames
23			COMPREPLY=( $(compgen -f -- $cur) )
24			return 0
25			;;
26		'-N'|'--task')
27			local TID='' I ARR
28			for I in /proc/*/mountinfo; do IFS=/ read -ra ARR <<< "$I"; TID+="${ARR[2]} "; done
29			COMPREPLY=( $(compgen -W "$TID" -- $cur) )
30			return 0
31			;;
32		'-O'|'--options')
33			local MTAB_3RD I
34			declare -a TMP_ARR
35			declare -A MNT_OPTS
36			while read MTAB_3RD; do
37				IFS=',' read -ra TMP_ARR <<<"$MTAB_3RD"
38				for I in ${TMP_ARR[@]}; do
39					MNT_OPTS[$I]='1'
40				done
41			done < <(findmnt -rno OPTIONS)
42			COMPREPLY=( $(compgen -W "${!MNT_OPTS[@]}" -- $cur) )
43			return 0
44			;;
45		'-o'|'--output')
46			# FIXME: how to append to a string with compgen?
47			local OUTPUT
48			OUTPUT="SOURCE TARGET FSTYPE OPTIONS VFS-OPTIONS
49				FS-OPTIONS LABEL UUID PARTLABEL PARTUUID
50				MAJ\:MIN ACTION OLD-TARGET OLD-OPTIONS
51				SIZE AVAIL USED USE% FSROOT TID ID
52				OPT-FIELDS PROPAGATION FREQ PASSNO"
53			compopt -o nospace
54			COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
55			return 0
56			;;
57		'-t'|'--types')
58			local TYPES
59			TYPES="adfs affs autofs cifs coda coherent cramfs
60				debugfs devpts efs ext ext2 ext3 ext4 hfs
61				hfsplus hpfs iso9660 jfs minix msdos
62				ncpfs nfs nfs4 ntfs proc qnx4 ramfs
63				reiserfs romfs squashfs smbfs sysv tmpfs
64				ubifs udf ufs umsdos usbfs vfat xenix xfs"
65			COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
66			return 0
67			;;
68		'-S'|'--source')
69			local DEV_MPOINT
70			DEV_MPOINT=$(findmnt -rno SOURCE | grep ^/dev)
71			COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
72			return 0
73			;;
74		'-T'|'--target')
75			local DEV_MPOINT
76			DEV_MPOINT=$(findmnt -rno TARGET)
77			COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
78			return 0
79			;;
80		'-h'|'--help'|'-V'|'--version')
81			return 0
82			;;
83	esac
84	case $cur in
85		-*)
86			OPTS="--fstab
87				--mtab
88				--kernel
89				--poll
90				--timeout
91				--all
92				--ascii
93				--canonicalize
94				--df
95				--direction
96				--evaluate
97				--tab-file
98				--first-only
99				--invert
100				--list
101				--task
102				--noheadings
103				--notruncate
104				--options
105				--output
106				--pairs
107				--raw
108				--types
109				--nofsroot
110				--submounts
111				--source
112				--target
113				--help
114				--version"
115			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
116			return 0
117			;;
118	esac
119	local DEV_MPOINT
120	DEV_MPOINT=$(findmnt -rno TARGET,SOURCE)
121	COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
122	return 0
123}
124complete -F _findmnt_module findmnt
125