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.

I'm using arch linux.

Is there a way to list optional dependencies of all installed packages? And if yes, can I filter this list to see only the missing (not installed) packages?

share|improve this question
    
I haven't used Arch, but "dependency" doesn't sound optional (it's not in other distros). –  jordanm Oct 28 '12 at 4:27
    
AFAIK, I don't think you can do that with pacman straight away. But it is very possible to write a small script to do it. Query pacman for list of installed packages. Have Yaourt fetch their PKGBUILDs and read the list of optdeps. The latest version of pacman-git has a commit that states whether the optdeps have already been installed. –  darnir Oct 28 '12 at 5:09
    
@jordanm: As has build dependencies and optional dependencies. Optdeps are required only for certain features of a package. So, unless you are using that feature, you don't really need to bloat your system with a load of dependencies. –  darnir Oct 28 '12 at 5:11

3 Answers 3

You can use expac to query the pacmandatabase.

Something like:

awk 'NF>=2' <(expac "%n %O") > optdeps

will print a list of all the installed packages on your machine and the optdepends for each one (%O)1 to a file called optdeps. You could then sort this against a list of installed optdepends packages.

See man expac for the complete list of options.


1. That is an upper case O, not a zero. Because we can't have a font that distinguished between the two...

share|improve this answer

Though I've had to notice that @DarkHeart's solution doesn't really work, it inspired me to make a working one. (no colours, though)

I'm using package-query, a similar tool instead of expac which was suggested by @jasonwryan, because I've had it already installed (it's a dependency of yaourt). It should be trivial to change this to use expac instead.

The listing of all optional dependencies is mostly done by the call to package-query. The first for-loop removes the explanations, so just the package names for the optional dependencies remain; the second for-loop removes the already installed dependencies in its first line before printing the results in the second one.

#!/usr/bin/perl
use strict;
use warnings;

my %deps;
for (`package-query -Q -f'%n %O'`) {
    $deps{ (/^(\S+)/)[0] } = [/(\S+):/g];
}
my @pkgs = keys %deps;
for my $pkg (@pkgs) {
    my @missing_deps = grep { !($_ ~~ @pkgs) } @{ $deps{$pkg} };
    print "$pkg => @missing_deps\n" if @missing_deps;
}
share|improve this answer

This is not exactly efficient, but will find what you want (in COLOR!):

pacman -Q > /tmp/paccache
for pkg in $(awk '{print $1}' /tmp/paccache) ; do 
   echo -n "$pkg => "; 
   for dep in $(pacman -Qi $pkg | awk -F: '/Optional Deps/{gsub(/[\<\>=].*/,"");print $NF;}' ) ; do 
       grep -q "$dep" /tmp/paccache && COLOR=32 ; echo -en "\e[1;${COLOR:-31}m${dep}\e[0;m " ; unset COLOR ; 
   done 
   echo
done 
share|improve this answer
    
I'm not perfectly sure, but shouldn't that be || instead of && after the grep, and then parentheses around the rest of the line? –  Rörd Nov 20 '12 at 21:10
    
And more importantly, this should probably use the "Optional Deps" section instead of the "Depends On" section of the pacman output. –  Rörd Nov 20 '12 at 22:28

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.