]>
Commit | Line | Data |
---|---|---|
76dceb10 SK |
1 | _lsblk_module() |
2 | { | |
c6b1d511 | 3 | local cur prev OPTS LSBLK_COLS_ALL |
76dceb10 SK |
4 | COMPREPLY=() |
5 | cur="${COMP_WORDS[COMP_CWORD]}" | |
6 | prev="${COMP_WORDS[COMP_CWORD-1]}" | |
b8446f75 | 7 | |
c6b1d511 SK |
8 | LSBLK_COLS_ALL=" |
9 | NAME KNAME MAJ:MIN FSTYPE MOUNTPOINT LABEL UUID PARTTYPE | |
10 | PARTLABEL PARTUUID PARTFLAGS RA RO RM HOTPLUG MODEL SERIAL SIZE | |
11 | STATE OWNER GROUP MODE ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC | |
12 | ROTA SCHED RQ-SIZE TYPE DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO | |
13 | WSAME WWN RAND PKNAME HCTL TRAN SUBSYSTEMS REV VENDOR | |
14 | " | |
b8446f75 | 15 | |
76dceb10 SK |
16 | case $prev in |
17 | '-e'|'--exclude'|'-I'|'--include') | |
b5b80e5a BE |
18 | local realcur prefix MAJOR_ALL MAJOR I J |
19 | realcur="${cur##*,}" | |
20 | prefix="${cur%$realcur}" | |
76dceb10 SK |
21 | for I in /sys/dev/block/*; do |
22 | J=${I##*/} | |
c6f0bdfe | 23 | MAJOR_ALL="${MAJOR_ALL:-""} ${J%%:*}" |
b5b80e5a | 24 | done |
c6f0bdfe | 25 | for WORD in ${MAJOR_ALL:-""}; do |
b5b80e5a | 26 | if ! [[ $prefix == *"$WORD"* ]]; then |
c6f0bdfe | 27 | MAJOR="$WORD ${MAJOR:-""}" |
b5b80e5a | 28 | fi |
76dceb10 | 29 | done |
76dceb10 | 30 | compopt -o nospace |
c6f0bdfe | 31 | COMPREPLY=( $(compgen -P "$prefix" -W "${MAJOR:-""}" -S ',' -- $realcur) ) |
76dceb10 SK |
32 | return 0 |
33 | ;; | |
ba5e7b7e | 34 | '-o'|'--output'|'-M'|'--dedup') |
b5b80e5a BE |
35 | local prefix realcur LSBLK_COLS |
36 | realcur="${cur##*,}" | |
37 | prefix="${cur%$realcur}" | |
38 | for WORD in $LSBLK_COLS_ALL; do | |
39 | if ! [[ $prefix == *"$WORD"* ]]; then | |
c6f0bdfe | 40 | LSBLK_COLS="$WORD ${LSBLK_COLS:-""}" |
b5b80e5a BE |
41 | fi |
42 | done | |
76dceb10 | 43 | compopt -o nospace |
b5b80e5a | 44 | COMPREPLY=( $(compgen -P "$prefix" -W "$LSBLK_COLS" -S ',' -- $realcur) ) |
b8446f75 KZ |
45 | return 0 |
46 | ;; | |
47 | '-x'|'--sort') | |
48 | compopt -o nospace | |
b5b80e5a | 49 | COMPREPLY=( $(compgen -W "$LSBLK_COLS_ALL" -- $cur) ) |
76dceb10 SK |
50 | return 0 |
51 | ;; | |
d4f9b8d7 VS |
52 | '-h'|'--help'|'-V'|'--version') |
53 | return 0 | |
54 | ;; | |
76dceb10 SK |
55 | esac |
56 | case $cur in | |
57 | -*) | |
0d5b9b8a VS |
58 | OPTS="--all |
59 | --bytes | |
60 | --nodeps | |
61 | --discard | |
62 | --exclude | |
63 | --fs | |
64 | --help | |
65 | --include | |
c6b1d511 | 66 | --json |
0d5b9b8a VS |
67 | --ascii |
68 | --list | |
ba5e7b7e SK |
69 | --dedup |
70 | --merge | |
0d5b9b8a VS |
71 | --perms |
72 | --noheadings | |
73 | --output | |
c6b1d511 SK |
74 | --output-all |
75 | --paths | |
0d5b9b8a VS |
76 | --pairs |
77 | --raw | |
78 | --inverse | |
79 | --topology | |
80 | --scsi | |
b8446f75 | 81 | --sort |
0d5b9b8a VS |
82 | --help |
83 | --version" | |
76dceb10 SK |
84 | COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) |
85 | return 0 | |
86 | ;; | |
87 | esac | |
0c8865f8 | 88 | compopt -o bashdefault -o default |
396a6d7d | 89 | COMPREPLY=( $(compgen -W "$($1 -pnro name)" -- $cur) ) |
76dceb10 SK |
90 | return 0 |
91 | } | |
92 | complete -F _lsblk_module lsblk |