Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In bash, it's easy enough to set up customized completion of command arguments using the complete built-in. For example, if, for a hypothetical command with a synopsis of foo --a | --b | --c, you could do complete -W '--a --b --c' foo

You can also customize the completion you get when you press Tab at an empty prompt using complete -E, e.g., complete -E -W 'foo bar'. Then pressing tab at the empty prompt would suggest only foo and bar.

How do I customize command completion at a non-empty prompt? E.g., if I'm sitting at:

anthony@Zia:~$ f

how do customize completion so pressing tab would always complete to foo?

(The actual case I'd like is locTABlocalc. And my brother, who prompted me to ask this, wants it with mplayer).

share|improve this question
2  
Have you considered simply aliasing loc to localc? I suggest alternatives because after quite some time digging and searching I have not found a way to customize bash completion this way. It may not be possible. –  jw013 Aug 5 at 20:47
    
@jw013 Yeah, I looked for a while and couldn't find anything either. I'm half expecting someone to suggest switching to zsh, too. At least if zsh does it, I can rest comfortably knowing the next version of bash will as well. 😀 –  derobert Aug 5 at 20:51
    
you have to press TAB twice and it will complete commands. –  Floyd Oct 10 at 15:30
    
Won't that break all the other completions though? I mean, even if it is possible, you would no longer be able to get locate, locale, lockfile or any of the other expansions of loc. Perhaps a better approach would be to map a different key to that specific completion. –  terdon Oct 28 at 18:00
    
@terdon Well, that'd depend on the programmable completion I installed. But yeah, I might have to type lock<TAB> or loca<TAB> to avoid loc<TAB>->localc. But I'd actually like to make it context-sensitive, which is why programmable completion would be nice... –  derobert Oct 28 at 19:43

3 Answers 3

I don't know if I unterstood your need for this...
This would imply that your bash only knows one command beginning with f.
A basic idea of completion is: if it's ambiguous, print the possiblities.
So you could set your PATH to a directory only containing this one command and disable all bash builtins to get this work.

Anyhow, I can give you also a kind of workaround:

alias _='true &&'
complete -W foo _

So if you type _ <Tab> it will complete to _ foo which executes foo.

But nethertheless the alias f='foo' would be much easier.

share|improve this answer

Simple answer for you would be to

$ cd into /etc/bash_completion.d $ ls

just the basic outputs

autoconf       gpg2               ntpdate           shadow
automake       gzip               open-iscsi        smartctl
bash-builtins  iconv              openssl           sqlite3
bind-utils     iftop              perl              ssh
brctl          ifupdown           pkg-config        strace
bzip2          info               pm-utils          subscription-manager
chkconfig      ipmitool           postfix           tar
configure      iproute2           procps            tcpdump
coreutils      iptables           python            util-linux
cpio           lsof               quota-tools       wireless-tools
crontab        lvm                redefine_filedir  xmllint
cryptsetup     lzma               rfkill            xmlwf
dd             make               rpm               xz
dhclient       man                rsync             yum.bash
e2fsprogs      mdadm              scl.bash          yum-utils.bash
findutils      module-init-tools  service
getent         net-tools          sh

just add your desired program to auto complete to bash completion

share|improve this answer
2  
Those files have shell script in them, some fairly complex if I remember correctly. Also, they only complete arguments once you've already typed the command... They don't complete the command. –  derobert Sep 25 at 3:41
    
I understand what you mean. When you can take a look at this doc: debian-administration.org/article/316/… –  unixmiah Sep 25 at 3:53

Run the below command to find where mplayer binary is installed:

which mplayer

OR use the path to the mplayer binary if you aleady know it, in the below command:

ln -s /path/to/mplayer /bin/mplayer

Ideally anything you type is searched in all directories specified in the $PATH variable.

share|improve this answer
1  
Hi, Mathew, welcome to Unix & Linux. I think the OP's question is a little more complicated than the answer you're suggesting. I presume mplayer is already in their $PATH and they want something like mp<tab> to produce mplayer, instead of all the binaries that begin with mp (e.g., mpage mpcd mpartition mplayer etc.) –  drs Oct 15 at 14:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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