]> git.ipfire.org Git - thirdparty/util-linux.git/blob - bash-completion/findmnt
7270d3616cf057f6ef1bac439dd64d787b0a871f
[thirdparty/util-linux.git] / bash-completion / findmnt
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 < <($1 -rno OPTIONS)
42 COMPREPLY=( $(compgen -W "${!MNT_OPTS[@]}" -- $cur) )
43 return 0
44 ;;
45 '-o'|'--output')
46 local prefix realcur OUTPUT_ALL OUTPUT
47 realcur="${cur##*,}"
48 prefix="${cur%$realcur}"
49
50 OUTPUT_ALL="SOURCE TARGET FSTYPE OPTIONS VFS-OPTIONS
51 FS-OPTIONS LABEL UUID PARTLABEL PARTUUID
52 MAJ\:MIN ACTION OLD-TARGET OLD-OPTIONS
53 SIZE AVAIL USED USE% FSROOT TID ID
54 OPT-FIELDS PROPAGATION FREQ PASSNO"
55
56 for WORD in $OUTPUT_ALL; do
57 if ! [[ $prefix == *"$WORD"* ]]; then
58 OUTPUT="$WORD ${OUTPUT:-""}"
59 fi
60 done
61 compopt -o nospace
62 COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) )
63 return 0
64 ;;
65 '-t'|'--types')
66 local TYPES
67 TYPES="adfs affs autofs cifs coda coherent cramfs
68 debugfs devpts efs ext2 ext3 ext4 hfs
69 hfsplus hpfs iso9660 jfs minix msdos
70 ncpfs nfs nfs4 ntfs proc qnx4 ramfs
71 reiserfs romfs squashfs smbfs sysv tmpfs
72 ubifs udf ufs umsdos usbfs vfat xenix xfs"
73 COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
74 return 0
75 ;;
76 '-S'|'--source')
77 local DEV_MPOINT
78 DEV_MPOINT=$($1 -rno SOURCE | grep ^/dev)
79 COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
80 return 0
81 ;;
82 '-T'|'--target')
83 local DEV_MPOINT
84 DEV_MPOINT=$($1 -rno TARGET)
85 COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
86 return 0
87 ;;
88 '-M'|'--mountpoint')
89 local IFS=$'\n'
90 compopt -o filenames
91 COMPREPLY=( $(compgen -o dirnames -- ${cur:-"/"}) )
92 return 0
93 ;;
94 '-h'|'--help'|'-V'|'--version')
95 return 0
96 ;;
97 esac
98 case $cur in
99 -*)
100 OPTS="--fstab
101 --mtab
102 --kernel
103 --poll
104 --timeout
105 --all
106 --ascii
107 --canonicalize
108 --df
109 --direction
110 --evaluate
111 --tab-file
112 --first-only
113 --invert
114 --json
115 --list
116 --task
117 --noheadings
118 --notruncate
119 --options
120 --output
121 --output-all
122 --pairs
123 --raw
124 --types
125 --nofsroot
126 --submounts
127 --source
128 --target
129 --mountpoint
130 --help
131 --tree
132 --real
133 --pseudo
134 --version"
135 COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
136 return 0
137 ;;
138 esac
139 local DEV_MPOINT
140 DEV_MPOINT=$($1 -rno TARGET,SOURCE)
141 COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
142 return 0
143 }
144 complete -F _findmnt_module findmnt