You are not logged in.
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
.
p.s.: When it's done I'll put it on my ftp server (or in incoming) for testing...
Offline
Ugly solution, but it seems to work:
pacman -Ss test | grep -v "^ " | cut -d "/" -f 2 | cut -d " " -f 1
Offline
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
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
Thanx a lot. This command (romankreisel's) did the job :
pacman -Ss | grep -v "^ " |cut -d "/" -f2 | cut -d " " -f 1I thought about using grep & cut (since I've used them in other parts on my completion script
) 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
Offline
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 ![]()
Offline
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
)
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
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-nameKeep in mind that bash has also several sed built-in functions:
[orelien@pikachu orelien]$ pkgname="tptp"; echo ${pkgname//p/o}
totoNot really portable, but very powerfull ![]()
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%-*-*}; doneBTW, 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
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
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 ![]()
Offline