bash tab completion doesn't work on shell scripts

0

1

On my Fedora 19 system tab completion doesn't work for bash scripts when I have a sh at the beginning of the command line unless the script filename ends with a .sh.

That is, if I type:

$ sh file<tab>

And the current directory contains:

filename

...tab completion doesn't work.

But if the current directory contains:

filename.sh

Completion works.

Completion works for everything else, so I suspect that there is a custom completer for commands that begin with sh and it is looking for files that end .sh.

Is there an easy way to fix this? I want to fix it for my user, not for all users, because I don't want to modify the operating system.

vy32

Posted 2013-07-17T11:12:24.510

Reputation: 2 715

1As @AlexanderPoteriachin pointed out, if you type filename yourself and the file is named filename there nothing more to complete. Do you mean you type e.g. only filen and [TAB] is not working? – mpy – 2013-07-17T11:36:56.133

Answers

8

The most basic commands to customize your completions in bash are:

  • To only complete .sh files after (G stands for globbing):

    complete -G '*.sh' sh
    

    Probably this is somewhere in your (system wide) config. (You can check with complete -pr which prints all definitions)

  • To complete any filename after sh just issue

    complete -A file sh
    

    -A takes much more possible actions (here: file), please check out the description of the complete builtin in man bashbuiltins for much more options.

For a permanent fix of that behavior, put the last command also to your ~/.bashrc.

mpy

Posted 2013-07-17T11:12:24.510

Reputation: 20 866

How to enable completions of current directory's files after ./ when not using sh command ? – Vicky Dev – 2018-09-21T00:49:55.057

@VickyDev: Although I don't fully understand what your question is, it sound like it'd better suit as a new question. – mpy – 2018-09-21T17:23:41.197

0

No, there should be anything custom. Haven't seen on anything like that on any Linux version. The tab completion works as expected.

By the way, what is the point

$ sh filename<tab>

of that anyway if you have "filename" in your directory?

Maybe you're confused a little bit, as if you have two similar filenames in a directory, the completion only goes until the characters are the same and then it shows all available options.

Ashtray

Posted 2013-07-17T11:12:24.510

Reputation: 1 489