bash-completion: readline expand-tilde not acknowledged
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
bash-completion (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: bash-completion
_expand() in /etc/bash_
Typing 'ls ~/<tab>' currently results in the command being expanded to 'ls /home/user/', even with readline's expand-tilde set to off.
Current _expand():
_expand()
{
# FIXME: Why was this here?
#[ "$cur" != "${cur%\\}" ] && cur="$cur\\"
# Expand ~username type directory specifications. We want to expand
# ~foo/... to /home/foo/... to avoid problems when $cur starting with
# a tilde is fed to commands and ending up quoted instead of expanded.
if [[ "$cur" == \~*/* ]]; then
eval cur=$cur
elif [[ "$cur" == \~* ]]; then
COMPREPLY=( $( compgen -P '~' -u "$cur" ) )
[ ${#COMPREPLY[@]} -eq 1 ] && eval COMPREPLY[
return ${#COMPREPLY[@]}
fi
}
The problem lies in the area "eval cur=$cur" as it should only do this expansion if readline's expand-tilde is on.
The following fixes it:
_expand()
{
# FIXME: Why was this here?
#[ "$cur" != "${cur%\\}" ] && cur="$cur\\"
# Expand ~username type directory specifications. We want to expand
# ~foo/... to /home/foo/... to avoid problems when $cur starting with
# a tilde is fed to commands and ending up quoted instead of expanded.
if [[ "$cur" == \~*/* ]]; then
if [ $(bind -v|grep 'set expand-tilde on'> /dev/null) ]; then
eval cur=$cur
else
return 0;
fi
elif [[ "$cur" == \~* ]]; then
COMPREPLY=( $( compgen -P '~' -u "$cur" ) )
[ ${#COMPREPLY[@]} -eq 1 ] && eval COMPREPLY[
return ${#COMPREPLY[@]}
fi
}
This function does perform the intended fix however there may be a more effective and efficient manner of resolving this. This still needs to be verified and tested further (for example, in the context of a script versus the command line).
If Ubuntu chooses to set the system-wide default of readline's expand-tilde to on, that would be acceptable so long as a user may then reconfigure it for a given system or user.
I was trying to set my tilde-expansion to OFF all of last night and was up to 4 AM trying to figure out why my inputrc-file wasn't recognizing 'set expand-tilde Off'. GRRR, stupid bash_completion doing whatever it wants to without checking user settings first.