7

Let's say I have a directory with a few files in it like this:

$ ls
file1  file2  file3

And I want to do some tab completion in bash:

$ cat file<tab>
file1  file2  file3  

I remember seeing someone doing tab completion and the shell bolded the next parts, so in this case, it would bold the 1, 2 and 3 of the filename so it'll look like this: file1 file2 file3

which will tell you what you should type in next.

I think this was a feature of zsh, but is there any way to get it in bash?

Amandasaurus
  • 30,211
  • 62
  • 184
  • 246

3 Answers3

2

In Red Hat based distros there is a package bash-completion. This package fills the /etc/bash_completion.d/ directory with specific completion behaviour for several programs. I'm using it under Fedora, Red Hat and CentOS.

yum install bash-completion
ghm1014
  • 944
  • 1
  • 5
  • 14
2

I don't know of directly ported functionality, but there is a way to hack this in bash. Programmable completion allows you to specify what you'd like to see when you hit that tab key dependent on the calling program, allowing (as a popular example) ssh [tab] to show autocomplete options from ~/.ssh/known_hosts.

Here are some useful resources:

Intro, Source and RPMs

User contributed "completions"

More examples

And more examples

Of course, to duplicate the functionality you specify above, you'll have to get down and dirty with the programmable aspect of completion and write your own functions. Ubuntu ships its own set of user contributed completions, which are a good starting point.

Andy
  • 5,190
  • 23
  • 34
1

I'm using tcsh because of a similar feature.

Here is my /etc/csh.cshrc file :

if ($?tcsh && $?prompt) then

   bindkey "\e[1~" beginning-of-line # Home
   bindkey "\e[7~" beginning-of-line # Home rxvt
   bindkey "\e[2~" overwrite-mode    # Ins
   bindkey "\e[3~" delete-char       # Delete
   bindkey "\e[4~" end-of-line       # End
   bindkey "\e[8~" end-of-line       # End rxvt

   bindkey -k up history-search-backward
   bindkey -k down history-search-forward

   set filec
   set prompt="[%B%m%b:%~] %n%# "
   set complete = enhance            # important line
   set autolist                      # important line too
   alias ls 'ls -hA --color'
   alias ll 'ls -l'
endif
Julien
  • 500
  • 1
  • 5
  • 11