8

If I type cat ~/.bashr<TAB> then it completes to cat ~/.bashrc.

If I type vim ~/.bashr<TAB> then it completes to vim /home/neil/.bashrc...

(It does the same with vi, which is aliased to "vim".)

Can I turn that off?

0

2 Answers 2

6

this is controlled by /etc/bash_completion

you can comment out the expansion code in _expand() if you don't like it.

here is my version in fedora 17, but yours should be similar:

# This function expands tildes in pathnames
#
_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
        cur=${cur#\~}
        COMPREPLY=( $( compgen -P '~' -u "$cur" ) )
        [ ${#COMPREPLY[@]} -eq 1 ] && eval COMPREPLY[0]=${COMPREPLY[0]}
        return ${#COMPREPLY[@]}
    fi
}
3
  • 1
    The location of completion scripts depends entirely on your system.
    – Daniel Beck
    Jun 28, 2012 at 19:42
  • hmm, maybe. thanks. i only use ubuntu/fedora/centos these days and it seems that the file is there. yeah, if it is another distro i can imagine that the file/function is located elsewhere, but still it is likely still controlled just by a text file.
    – johnshen64
    Jun 28, 2012 at 19:44
  • 4
    Thanks, I "fixed" my problem by defining a function _expand() { :;} in my ~/.bashrc.
    – Neil
    Jun 28, 2012 at 23:44
6

bash can provide more sophisticated autocompletion for certain commands (e.g. autocompleting program arguments other than file names). There is such a Programmable Completion function defined for the vim command on your system.

Typing complete at the command prompt will show you what functions are used to provide autocompletion for bash.

$ complete
complete -o default -F _complete_open open

Type type function_name to learn about their definition.

$ type _complete_open
_complete_open is a function
_complete_open () 
{ 
   # function definition
}

To find out where the function was defined. use the following:

$ shopt -s extdebug
$ declare -F _complete_open
_complete_open 70 /Users/danielbeck/.bash_profile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.