Skip to content

Instantly share code, notes, and snippets.

@moverest
Last active January 20, 2017 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moverest/b2f67663adb70d48adbc14be50691cae to your computer and use it in GitHub Desktop.
Save moverest/b2f67663adb70d48adbc14be50691cae to your computer and use it in GitHub Desktop.
function get_packages
pacman -Qq
end
function get_exec_from_package --argument-names pkg
set -l lines (pacman -Ql $pkg | string match -r "/usr/bin/(.+)|/usr/sbin/(.+)")
while set -q lines[2]
echo $lines[2]
set -e lines[1..2]
end
end
set -l count_total 0
set -l count_matching 0
set -l count_total_fishcompleted 0
set -l count_matching_fishcompleted 0
for pkg in (get_packages)
for cmd in (get_exec_from_package $pkg)
set count_total (math "$count_total + 1")
if test $cmd = $pkg
set count_matching (math "$count_matching + 1")
end
if test -e /usr/share/fish/completions/$cmd.fish
set count_total_fishcompleted (math "$count_total_fishcompleted + 1")
if test $cmd = $pkg
set count_matching_fishcompleted (math "$count_matching_fishcompleted + 1")
end
echo + $cmd $pkg
else
echo - $cmd $pkg
end
end
end
echo $count_matching $count_total
echo $count_matching_fishcompleted $count_total_fishcompleted
@faho
Copy link

faho commented Jan 20, 2017

A few comments:

  • get_packages can be simplified to pacman -Qq.

  • get_exec_from_package can also be simplified with pacman -Qlq (so it doesn't print the package name anymore, so you don't need a capturing group). pacman -Qlq | string match -r "/usr/bin/.+" should work (the sbin is also superfluous on arch).

@moverest
Copy link
Author

I wasn't expecting that, but I like the fact that you took the time to comment on this code. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment