Initial implementation of _reply_compgen_array
This commit is contained in:
parent
6663709d76
commit
99b289474e
@ -7,6 +7,37 @@
|
|||||||
have mount &&
|
have mount &&
|
||||||
{
|
{
|
||||||
|
|
||||||
|
# Just like COMPREPLY=(`compgen -W "${COMPREPLY[*]}" -- "$cur"`), only better!
|
||||||
|
# This will correctly escape special characters in COMPREPLY.
|
||||||
|
_reply_compgen_array()
|
||||||
|
{
|
||||||
|
# Create the argument for compgen -W by escaping twice.
|
||||||
|
#
|
||||||
|
# One round of escape is because we want to reply with escaped arguments. A
|
||||||
|
# second round is required because compgen -W will helpfully expand it's
|
||||||
|
# argument.
|
||||||
|
local wlist
|
||||||
|
for i in ${!COMPREPLY[*]}; do
|
||||||
|
local q=`printf %q "${COMPREPLY[$i]}"`
|
||||||
|
wlist+=$(quote "$q")$'\n'
|
||||||
|
done
|
||||||
|
|
||||||
|
# We also have to add another round of escaping to $cur.
|
||||||
|
local ecur="$cur"
|
||||||
|
ecur="${ecur//\\/\\\\}"
|
||||||
|
ecur="${ecur/#$\'/\$\'}"
|
||||||
|
|
||||||
|
# Actually generate completions.
|
||||||
|
IFS=$'\n' eval 'COMPREPLY=(`compgen -W "$wlist" -- "${ecur}"`)'
|
||||||
|
|
||||||
|
# Strip starting $' in reply if present in cur.
|
||||||
|
# This is necesarry because readline interprets everything after ' as a
|
||||||
|
# separate word for completion.
|
||||||
|
if [[ $cur == $\'* ]]; then
|
||||||
|
COMPREPLY=( "${COMPREPLY[@]/#$\'}" )
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
_mount()
|
_mount()
|
||||||
{
|
{
|
||||||
local cur sm host prev
|
local cur sm host prev
|
||||||
@ -48,7 +79,14 @@ _mount()
|
|||||||
elif [ $prev = -U ]; then
|
elif [ $prev = -U ]; then
|
||||||
COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) )
|
COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) )
|
||||||
else
|
else
|
||||||
COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' /etc/fstab )" -- "$cur" ) )
|
COMPREPLY=()
|
||||||
|
while read -r fs_spec fs_file fs_other; do
|
||||||
|
if [[ $fs_spec = [#]* ]]; then continue; fi
|
||||||
|
[[ $fs_spec = */* ]] && { IFS=$'\0' eval "COMPRELPY+=( $'$fs_spec' )"; }
|
||||||
|
[[ $fs_file = */* ]] && { IFS=$'\0' eval "COMPREPLY+=( $'$fs_file' )"; }
|
||||||
|
done < /etc/fstab
|
||||||
|
|
||||||
|
_reply_compgen_array
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user