]> git.ipfire.org Git - thirdparty/util-linux.git/blob - bash-completion/findmnt
bash-completion: Don't offer any more completions after help or version.
[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 compopt -o filenames
22 COMPREPLY=( $(compgen -f -- $cur) )
23 return 0
24 ;;
25 '-N'|'--task')
26 local TID='' I ARR
27 for I in /proc/*/mountinfo; do IFS=/ read -ra ARR <<< "$I"; TID+="${ARR[2]} "; done
28 COMPREPLY=( $(compgen -W "$TID" -- $cur) )
29 return 0
30 ;;
31 '-O'|'--options')
32 local MTAB_3RD I
33 declare -a TMP_ARR
34 declare -A MNT_OPTS
35 while read MTAB_3RD; do
36 IFS=',' read -ra TMP_ARR <<<"$MTAB_3RD"
37 for I in ${TMP_ARR[@]}; do
38 MNT_OPTS[$I]='1'
39 done
40 done < <(findmnt -rno OPTIONS)
41 COMPREPLY=( $(compgen -W "$(echo ${!MNT_OPTS[@]})" -- $cur) )
42 return 0
43 ;;
44 '-o'|'--output')
45 # FIXME: how to append to a string with compgen?
46 local OUTPUT
47 OUTPUT="SOURCE TARGET FSTYPE OPTIONS VFS-OPTIONS
48 FS-OPTIONS LABEL UUID PARTLABEL PARTUUID
49 MAJ\:MIN ACTION OLD-TARGET OLD-OPTIONS
50 SIZE AVAIL USED USE% FSROOT TID ID
51 OPT-FIELDS PROPAGATION FREQ PASSNO"
52 compopt -o nospace
53 COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
54 return 0
55 ;;
56 '-t'|'--types')
57 local TYPES
58 TYPES="adfs affs autofs cifs coda coherent cramfs
59 debugfs devpts efs ext ext2 ext3 ext4 hfs
60 hfsplus hpfs iso9660 jfs minix msdos
61 ncpfs nfs nfs4 ntfs proc qnx4 ramfs
62 reiserfs romfs squashfs smbfs sysv tmpfs
63 ubifs udf ufs umsdos usbfs vfat xenix xfs
64 xiafs"
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="-s --fstab
87 -m --mtab
88 -k --kernel
89 -p --poll
90 -w --timeout
91 -A --all
92 -a --ascii
93 -c --canonicalize
94 -D --df
95 -d --direction
96 -e --evaluate
97 -F --tab-file
98 -f --first-only
99 -i --invert
100 -l --list
101 -N --task
102 -n --noheadings
103 -u --notruncate
104 -O --options
105 -o --output
106 -P --pairs
107 -r --raw
108 -t --types
109 -v --nofsroot
110 -R --submounts
111 -S --source
112 -T --target
113 -h --help
114 -V --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 }
124 complete -F _findmnt_module findmnt