Last active
January 20, 2017 23:20
-
-
Save moverest/b2f67663adb70d48adbc14be50691cae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
A few comments:
get_packages
can be simplified topacman -Qq
.get_exec_from_package
can also be simplified withpacman -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).