You are not logged in.

#1 2009-08-21 15:01:56

ConnorBehan
Package Maintainer (PM)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,359
Website

Customizing tab completion in a shell?

My experience with shells other than bash is very limited but I think other people might be able to help:

Let's say I'm recompiling the kernel. When finished, my pwd will have the files: kernel26-2.6.30.4-1-i686.pkg.tar.gz, kernel26.install and kernel26.preset.

Now what I want to do (because I'm VERY lazy) is type:

pacman -U k

and then press tab, and have it fill in:

pacman -U kernel26-2.6.30.4-1-i686.pkg.tar.gz

however tab completion in bash doesn't do this. It stops at kernel26 because there are multiple files starting with that string.

I know this behaviour is useful but for a command like pacman, it doesn't make sense to have a ".install" file, a ".preset" file or indeed any text file as its argument. The only file that makes sense is the tar.gz file and if bash knew this its search could be narrowed down.

Is there a way to restrict what files bash considers in tab completion based on the command you've started typing? Like a config file where you specify commands and then specify allowed extensions or mime-types? Or is there another shell that allows this? Thanks.


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

#2 2009-08-21 15:04:37

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Customizing tab completion in a shell?

are you using bash completion? http://projects.archlinux.org/?p=pacman … on;hb=HEAD
I see references to pkg.tar.gz in there, for the -U operation, so it might do what you want


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#3 2009-08-21 15:10:47

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: Customizing tab completion in a shell?

pacman -S bash-completion
. /etc/bash_completion # or relogin

Then bash will complete pacman commands in the manner you describe. pacman, like many other programs, installs a file to /etc/bash_completion.d to implement special completion for pacman.

Offline

#4 2009-08-21 15:10:53

wonder
Developer
From: Bucharest, Romania
Registered: 2006-07-05
Posts: 5,941
Website

Re: Customizing tab completion in a shell?

you need to install bash-completion. pacman already provides the syntax for that.


Give what you have. To someone, it may be better than you dare to think.

Offline

#5 2009-08-21 20:13:38

ConnorBehan
Package Maintainer (PM)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,359
Website

Re: Customizing tab completion in a shell?

Ok I downloaded bash-completion and logged in again (in fact I rebooted) and I have tried the following.

mkdir foo
cd foo
touch bar.pkg.tar.gz
touch bar.install
pacman -U bar

then I press tab but ".pkg.tar.gz" is not filled in. Am I doing something wrong? Can you guys try and see what that gives you?


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

#6 2009-08-21 20:23:43

wonder
Developer
From: Bucharest, Romania
Registered: 2006-07-05
Posts: 5,941
Website

Re: Customizing tab completion in a shell?

don't do that. use a real package. you are just doing a file not an arhive.


Give what you have. To someone, it may be better than you dare to think.

Offline

#7 2009-08-21 20:56:00

ConnorBehan
Package Maintainer (PM)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,359
Website

Re: Customizing tab completion in a shell?

This is working now, thanks.

Last edited by ConnorBehan (2009-08-22 10:52:11)


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

Board footer

Powered by FluxBB