Skip to content

Instantly share code, notes, and snippets.

@najamelan
Last active August 23, 2022 16:45
Show Gist options
  • Save najamelan/714224baabeb99df87ef5b50a5474d01 to your computer and use it in GitHub Desktop.
Save najamelan/714224baabeb99df87ef5b50a5474d01 to your computer and use it in GitHub Desktop.
Arch pacman for humans
# Syntactic sugar for pacman
#
function print_pcm_usage
set blue ( set_color blue )
set green ( set_color green )
set bold ( set_color --bold )
set normal ( set_color normal )
echo "$blue
Usage:$normal
——————
pcm is a wrapper for pacman, the Arch package manager. Only basic operations are implemented
but you can pass extra arguments which will be passed to pacman.
For more advanced needs, check out `man pacman` or
https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks#Listing_packages.
$blue
Command Explanation pacman equivalent$normal
—————————————————————————————————————————————————————————————————————————————————————————————————————————
$bold pcm $normal Show this message
$bold pcm install $normal"$green"package"$normal" Update cache and Install the given package -S "$green"package"$normal"
$bold pcm remove $normal"$green"package"$normal" Remove the given package + deps that are orphaned -Rs "$green"package"$normal"
$bold pcm update $normal Update the package cache -Sy
$bold pcm upgrade $normal Upgrade all packages -Syu
$bold pcm clean $normal Autoremove orphaned dependencies pacman -Rns (pacman -Qtdq)
$bold pcm show $normal Show information on all packages -Qi
$bold pcm show $normal"$green"package"$normal" Show information on the given package -Qi "$green"package"$normal"
$bold pcm show sizes $normal Show the size of all packages -Qi"$blue"[1]$normal
$bold pcm search $normal"$green"regex"$normal" Search in package names and descriptions -Ss "$green"string"$normal"
$bold pcm list installed $normal List installed packages -Q
$bold pcm list orphans $normal List lingering dependencies -Qtdq
$bold pcm list installed manually $normal List explicitly installed packages -Qe
$bold pcm list installed aur $normal List installed from AUR -Qm
$bold pcm list depends $normal"$green"package"$normal" List dependencies"$blue"[2]$normal pactree -u
$bold pcm list revdepends $normal"$green"package"$normal" List reverse dependencies"$blue"[2]$normal pactree -ru
$bold pcm list files $normal"$green"package"$normal" List all the files in given package pacman --query --list "$green"package"$normal"
$bold pcm who owns $normal"$green" file"$normal" Search which package provides a certain file"$blue"[3]$normal pkgfile --search --regex --ignorecase "$green"file"$normal"
$bold pcm verify files $normal Verify the md5 hash of all files from packages"$blue"[4]$normal paccheck --md5sum --quiet
$bold pcm verify files $normal"$green"package"$normal" Verify the md5 hash of all files from a given package"$blue"[4]$normal paccheck --md5sum --quiet "$green"package"$normal"
"$blue"[1]$normal pacman -Qi | awk '/^Name/{name=$3} /^Installed Size/{print $4$5, name}' | sort -h
"$blue"[2]$normal requires installation of "$green"pacman-contrib"$normal"
"$blue"[3]$normal requires installation of "$green"pkgfile"$normal"
"$blue"[4]$normal requires installation of "$green"pacutils"$normal"
"
end
function pcm --description "A wrapper around pacman to make it usable for humans. Type pcm without arguments for documentation."
# Make sure we can test $argv without having to verify it's length first
#
set args $argv dummy dummy dummy dummy dummy
switch $args[ 1 ]
# No arguments where provided
#
case dummy help --help -h
print_pcm_usage
case update; set --erase argv[ 1 ]
yn pacman --sync --refresh $argv
case upgrade; set --erase argv[ 1 ]
yn pacman --sync --refresh --sysupgrade $argv
case install; set --erase argv[ 1 ]
yn pacman --sync $argv
case remove; set --erase argv[ 1 ]
yn pacman --remove --recursive $argv
case search; set --erase argv[ 1 ]
pacman --sync --search $argv
case clean; set --erase argv[ 1 ]
set orphans (pcm list orphans)
if test (count $orphans) -gt 0; pacman --remove --nosave --recursive $orphans
else; echo "No orphans to clean up"
end
case who; set --erase argv[ 1 ]
if test $args[ 2 ] = owns; set --erase argv[ 1 ]
pkgfile --search --regex --ignorecase $argv
else; pcm; end
case list; set --erase argv[ 1 ]
if test "$args[ 2..3 ]" = 'installed manually'; set --erase argv[ 1..2 ]
pacman --query --explicit $argv
else if test "$args[ 2..3 ]" = 'installed aur'; set --erase argv[ 1..2 ]
pacman --query --foreign $argv
else if test $args[ 2 ] = installed; set --erase argv[ 1 ]
pacman --query $argv
else if test $args[ 2 ] = orphans; set --erase argv[ 1 ]
pacman --query --unrequired --deps --quiet
else if test $args[ 2 ] = files; set --erase argv[ 1 ]
pacman --query --list $argv
else if test $args[ 2 ] = deps; set --erase argv[ 1 ]
pactree --unique $argv
else if test $args[ 2 ] = revdeps; set --erase argv[ 1 ]
pactree --reverse --unique $argv
else if test "$args[ 2..3 ]" = 'manually installed'; set --erase argv[ 1..2 ]
pacman --query --explicit $argv
else; pcm; end
case show; set --erase argv[ 1 ]
if test $args[ 2 ] = sizes; set --erase argv[ 1 ]
pacman --query --info | awk '/^Name/{name=$3} /^Installed Size/{print $4$5, name}' | sort -h
else
pacman --query --info $argv
end
case verify; set --erase argv[ 1 ]
if test $args[ 2 ] = files; set --erase argv[ 1 ]
echo "This might take awhile..."
paccheck --md5sum --quiet $argv
else; pcm; end
# Unknown arguments, forward to pacman
#
case '*'
yn pacman $argv
end
end
@najamelan
Copy link
Author

Rendered help message:
pcm rendered

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