#!/usr/bin/env bash # Pman - small `pacman` wrapper for everyday operations # Copyright (C) 2026 OldarkDesu # This program is free software; you can redistribute it and/or # meodify it under the terms of the GNU General Public License, version 2 # as published by the Free Software Foundation. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, see # . USE_COLOR=yes if [ -n "$NO_COLOR" ] ; then USE_COLOR= elif [ ! -t 1 ] ; then USE_COLOR= fi say() { local color local rst local outstr local error rst=$'\e[0m' if [ "$1" = '--err' -o "$1" = '-e' ] ; then color=$'\e[0;1;31m' error=yes shift elif [ "$1" = '--warn' -o "$1" = '-w' ] ; then color=$'\e[0;1;33m' error=yes shift else color=$'\e[0;1m' error='' fi # construct output string outstr="${USE_COLOR:+$color}[pman] ${USE_COLOR:+$rst} $@" # decide where to send string, stderr or stdout [ $error ] && echo $outstr >&2 || echo $outstr } ensure_cmd () { if ! command -v $1 >/dev/null ; then say --err "Command \`$1\` is not available" exit 1 fi } # check if doas/sudo if command -v doas >/dev/null && [ -f /etc/doas.conf ] 2>&1 ; then SUCMD=doas elif command -v sudo >/dev/null ; then SUCMD=sudo else say --err "Warning! Neither 'sudo' nor 'doas' is available." fi help_str="Usage: pman SUBCOMMAND [ARGUMENTS] [PACMAN-OPTIONS] Subcommands: install PACKAGE(S) install PACKAGE(S) Alases: i, in remove PACKAGE(S) remove PACKAGE(S) Aliases: r, re find PATTERN find PATTERN in local database Aliases: f, fi search PATTERN search PATTERN in remote repos Aliases: s, se find-exact PACKAGE(s) find PACKAGE(S) in local database Aliases: fx search-exact PACKAGE(S) search PACKAGE(S) in package repos Aliases: sx info PACKAGE get information about PACKAGE in the local database list list explicitly installed packages Aliases: l list-all list all installed packages Aliases: ll list-aur list explicitly installed packages that are available from the AUR list-aur-all list all installed packages that are available from the aur info-remote PACKAGE get information about PACKAGE in remote repos Aliases: ir, infore file-tree PACKAGE(S) print a tree of the files contained in Aliases: files PACKAGE(S) file-list PACKAGE(S) print a list of the files contained in PACKAGE(S) provides PACKAGE(S) lists the packages that provide listed commands owns PACKAGE(S) lists the package that owns each passed file autoremove automatically remove orphaned packages clean remove unneeded cached packages and sync databases clean-all remove all cached packages and sync databases refresh sync the package databases update-mirrors [COUNTRIES] update mirrorlist using reflector and optionally provide a list of country codes" if test $1 ; then case $1 in i | in | install ) $SUCMD pacman -S --needed ${@:2} ;; u | up | update ) $SUCMD pacman -Syu ${@:2} ;; r | re | remove ) $SUCMD pacman -Rns --confirm ${@:2} ;; f | fi | find ) say "Finding in remote repos..." pacman -Ss ${@:2} ;; fx | fix | fex | find-exact ) IFS='|' say "Finding ${@} in remote repos..." pacman -Ss "^(${*:2})$" ;; s | se | search ) say "Searching $2 in local database..." pacman -Qs $2 ;; sx | sex | search-exact ) say "Searching for ${@:2} in local database..." pacman -Q ${@:2} ;; info ) if [ -n "$3" ]; then say --err "Only one package name supported by \`pman info\`, ignoring the rest..." fi pacman -Qii $2 if [ $? -ne 0 ]; then say --err "\`$2\` not found in local database. Trying again with command \`$(basename $0) info-remote\`" pman info-remote $2 fi ;; ir | infore | info-remote ) if [ -n "$3" ]; then say --warn "Only one package name supported by \`pman info-remote\`, ignoring the rest..." >&2 fi pacman -Sii $2 if [ $? -ne 0 ]; then say --err "Could not find $2, try \`$(basename $0) refresh && $(basename $0) info $2\`" >&2 exit 1 fi ;; autoremove ) TARGETS="$(pacman -Qdttnq)" if [ -z "$TARGETS" ] ; then say "Nothing to remove" else echo "$TARGETS" | $SUCMD pacman -Rns --confirm - fi ;; refresh) $SUCMD pacman -Sy ;; update-mirrors) ensure_cmd reflector $SUCMD reflector --latest 20 \ --sort rate \ --country ${2:-'US,CO,'} \ --save /etc/pacman.d/mirrorlist ;; c|clean ) $SUCMD pacman -Sc ;; cc|clean-all) $SUCMD pacman -Scc ;; h | he | hel | help ) echo "$help_str" ;; provides) pacman -F ${@:2} ;; owns) pacman -Qo ${@:2} ;; files|file-tree) ensure_cmd tree pacman -Fl ${@:2} | tree --fromfile ;; file-list) pacman -Fl ${@:2} ;; l|list|list-installed) pacman -Qe ;; ll|list-all) pacman -Q ;; list-aur) pacman -Qem ;; list-aur-all) pacman -Qm ;; * ) say --err "\`$1\` is not a recognized command" echo "$help_str" >&2 exit 1 ;; esac exit 0 else echo "$help_str" >&2 exit 1 fi