|
7 | 7 | have mount && |
8 | 8 | { |
9 | 9 |
|
| 10 | +# Just like COMPREPLY=(`compgen -W "${COMPREPLY[*]}" -- "$cur"`), only better! |
| 11 | +# This will correctly escape special characters in COMPREPLY. |
| 12 | +_reply_compgen_array() |
| 13 | +{ |
| 14 | + # Create the argument for compgen -W by escaping twice. |
| 15 | + # |
| 16 | + # One round of escape is because we want to reply with escaped arguments. A |
| 17 | + # second round is required because compgen -W will helpfully expand it's |
| 18 | + # argument. |
| 19 | + local wlist |
| 20 | + for i in ${!COMPREPLY[*]}; do |
| 21 | + local q=`printf %q "${COMPREPLY[$i]}"` |
| 22 | + wlist+=$(quote "$q")$'\n' |
| 23 | + done |
| 24 | + |
| 25 | + # We also have to add another round of escaping to $cur. |
| 26 | + local ecur="$cur" |
| 27 | + ecur="${ecur//\\/\\\\}" |
| 28 | + ecur="${ecur/#$\'/\$\'}" |
| 29 | + |
| 30 | + # Actually generate completions. |
| 31 | + IFS=$'\n' eval 'COMPREPLY=(`compgen -W "$wlist" -- "${ecur}"`)' |
| 32 | + |
| 33 | + # Strip starting $' in reply if present in cur. |
| 34 | + # This is necesarry because readline interprets everything after ' as a |
| 35 | + # separate word for completion. |
| 36 | + if [[ $cur == $\'* ]]; then |
| 37 | + COMPREPLY=( "${COMPREPLY[@]/#$\'}" ) |
| 38 | + fi |
| 39 | +} |
| 40 | + |
10 | 41 | _mount() |
11 | 42 | { |
12 | 43 | local cur sm host prev |
@@ -48,7 +79,14 @@ _mount() |
48 | 79 | elif [ $prev = -U ]; then |
49 | 80 | COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) ) |
50 | 81 | else |
51 | | - COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' /etc/fstab )" -- "$cur" ) ) |
| 82 | + COMPREPLY=() |
| 83 | + while read -r fs_spec fs_file fs_other; do |
| 84 | + if [[ $fs_spec = [#]* ]]; then continue; fi |
| 85 | + [[ $fs_spec = */* ]] && { IFS=$'\0' eval "COMPRELPY+=( $'$fs_spec' )"; } |
| 86 | + [[ $fs_file = */* ]] && { IFS=$'\0' eval "COMPREPLY+=( $'$fs_file' )"; } |
| 87 | + done < /etc/fstab |
| 88 | + |
| 89 | + _reply_compgen_array |
52 | 90 | fi |
53 | 91 | fi |
54 | 92 |
|
|
0 commit comments