You are not logged in.

#1 2003-10-03 18:20:35

zen_guerrilla
Member
From: Greece
Registered: 2002-12-22
Posts: 259

bash-completion for archlinux (need help)

Hello all,
I'm trying to create a bash-completion script for archlinux to auto-complete init scripts, makepkg & pacman. It's almost there, however I need some help. I want to format the output of 'pacman -Ss' to list only the names of the packages. Propably with sed, however I'm not really a sed wizard, so any help will be appreciated smile.

p.s.: When it's done I'll put it on my ftp server (or in incoming) for testing...

Offline

#2 2003-10-03 22:20:33

romankreisel
Member
Registered: 2003-08-07
Posts: 14

Re: bash-completion for archlinux (need help)

Ugly solution, but it seems to work:

pacman -Ss test | grep -v "^ " | cut -d "/" -f 2 | cut -d " " -f 1

Offline

#3 2003-10-03 22:45:29

red_over_blue
Member
Registered: 2003-07-19
Posts: 152

Re: bash-completion for archlinux (need help)

Here it is using sed:

 pacman -Ss | sed -e "/^ /d" -e "s:^unofficial/::g" -e "s:^current/::g" -e "s:^unstable/::g" -e "s: .*::g"

If you want to see the versions, just remove the -e "s: .*::g" at the end.


Don't forget to post your PKGBUILD in your thread when you announce a new package in incoming.
see HERE for details

Offline

#4 2003-10-03 22:47:28

red_over_blue
Member
Registered: 2003-07-19
Posts: 152

Re: bash-completion for archlinux (need help)

romankreisel,

I get weird results with yours:

[root@limbo root]# pacman -Ss test | grep -v "^ " | cut -d "/" -f 2 | cut -d " " -f 1
gscanbus
unarj
xbill
[root@limbo root]# 

Don't forget to post your PKGBUILD in your thread when you announce a new package in incoming.
see HERE for details

Offline

#5 2003-10-03 23:01:19

zen_guerrilla
Member
From: Greece
Registered: 2002-12-22
Posts: 259

Re: bash-completion for archlinux (need help)

Thanx a lot. This command (romankreisel's) did the job :

pacman -Ss | grep -v "^ " |cut -d "/" -f2 | cut -d " " -f 1

I thought about using grep & cut (since I've used them in other parts on my completion script smile) but dumped them due to their "ugliness". However sed is not really handy in this case after all, since someone could create his own repository (ie. [local]) and it won't be able to get auto-completed, unless the completion greps /etc/pacman.conf for [] but that increases its complexity.
Anyway thanx again & I'll keep you informed when the script is done. It's just needs some cleaning up now...

Offline

#6 2003-10-03 23:26:28

zen_guerrilla
Member
From: Greece
Registered: 2002-12-22
Posts: 259

Re: bash-completion for archlinux (need help)

Offline

#7 2003-10-04 08:17:38

orelien
Forum Fellow
From: France
Registered: 2002-12-05
Posts: 220
Website

Re: bash-completion for archlinux (need help)

IMHO, calling pacman to get a list of packages is highly overloading the bash completion mechanism...

You could just try to get the content of /var/lib/pacman/local to get installed packages, and /var/lib/pacman/{"all directories but local"} to get available packages.
It should be far more faster.

My 2 cents  wink

Offline

#8 2003-10-04 11:53:21

zen_guerrilla
Member
From: Greece
Registered: 2002-12-22
Posts: 259

Re: bash-completion for archlinux (need help)

orelien wrote:

You could just try to get the content of /var/lib/pacman/local to get installed packages, and /var/lib/pacman/{"all directories but local"} to get available packages. It should be far more faster.

This is how I tried to do it when I started writing the script. I have 2 problems however :

1) I don't know how to format the output of i.e. `ls /var/lib/pacman/local` to include only the pkg name & not the version. Some packages have 2 or 3 words separated with '-', so cut -d- is out of the question. I need some way to use cut with -d"-INTEGER" -f1 (aka stop when you find a number and pass the first part).
2) The code for listing the available packages would be much more complicated IMHO (not a big problem though the script is already quite complicated smile)

However using pacman it is slow only when you first run ie. `pacman -S [tab]`, afterwards it's ok.
Well, any suggestions are welcome and if someone could help with problem (1) of that approach, I'll give it a try.

Another thing I need is a way to make short, single dashed-commands (ie. -b) and double-dashed (ie. --builddeps) [that do the same thing] equal, so that when someone runs ie :

makepkg -b -[tab] 

both -b --builddeps would dissappear from the list of available options. (this is what the rem_selected() function does with only one command though).

Offline

#9 2003-10-05 18:57:23

orelien
Forum Fellow
From: France
Registered: 2002-12-05
Posts: 220
Website

Re: bash-completion for archlinux (need help)

zen_guerilla wrote:

1) I don't know how to format the output of i.e. `ls /var/lib/pacman/local` to include only the pkg name & not the version.

No need for awk, sed nor cut for this kind of operations:

[orelien@pikachu orelien]$ pkgnamefull="pkg-name-0.1-1"
[orelien@pikachu orelien]$ pkgname=${pkgnamefull%-*-*}
[orelien@pikachu orelien]$ echo $pkgname
pkg-name

Keep in mind that bash has also several sed built-in functions:

[orelien@pikachu orelien]$ pkgname="tptp"; echo ${pkgname//p/o}
toto

Not really portable, but very powerfull wink

zen_guerilla wrote:

2) The code for listing the available packages would be much more complicated

To get the whole list of available packages, you can try something like (although maybe not really optimized?):

pkgs=$(ls --ignore=local /var/lib/pacman | (cd /var/lib/pacman; xargs ls -1 | grep -v "^$" | grep -v ":$" | sort))
for i in $pkgs; do echo ${i%-*-*}; done

BTW, it makes me think that it could be useful to have "pacman -S" displaying the whole list of available packages. Added to pacman TODO list.

Offline

#10 2003-10-05 21:04:51

zen_guerrilla
Member
From: Greece
Registered: 2002-12-22
Posts: 259

Re: bash-completion for archlinux (need help)

orelien thanx a lot for the suggestions, I added them on v.0.7 of the script, that can be found at http://147.27.11.72/manolis/archlinux/archlinux
Pls check it out & report any possible bugs, or suggestions for new features/improvements. I guess v.1.0 could get included in the bash-completion package...

Offline

#11 2006-05-27 07:28:17

drakosha
Member
Registered: 2006-01-03
Posts: 253
Website

Re: bash-completion for archlinux (need help)

I have a suggestion to one more completion: there's a tool named "atool" which is archiver/unarchiver for every archive format you can think of. It's just a wrapper of unzip, zip, unrar, rar, gzip, bzip2, tar, etc'. I'd like very much to see a completion for it.
So, bash magicians - it's a job for you smile

Offline

Board footer

Powered by FluxBB