diff --git a/README.md b/README.md index baa4a25..ed236cb 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ # pman.sh +A `pacman` helper script, because you forget the stupid flags + +## Usage / Features: +- search +- update +- upgradable +- upgrade +- install +- provides +- config + +`config` is the only flag that is not appended to `pacman`, instead it resolves to `nano /etc/pacman.conf`. + +`sudo` gets prepended automatically if the command requires it and if installed - no, there is no check if your user is in the `sudo` group, if you download this script you should already be, or know you can only use part of this utility diff --git a/pman.sh b/pman.sh new file mode 100755 index 0000000..18e691b --- /dev/null +++ b/pman.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# Store the first command line argument in the variable "command" and shift the rest +command="$1" +shift + +# Evaluate the command +if [ "$command" = "search" ]; then + command="pacman" + command_args="-Ss" +elif [ "$command" = "update" ]; then + command="pacman" + command_args="-Sy" + su_needed=true +elif [ "$command" = "upgradable" ]; then + command="pacman" + command_args="-Qu" +elif [ "$command" = "upgrade" ]; then + command="pacman" + command_args="-Syu" + su_needed=true +elif [ "$command" = "install" ]; then + command="pacman" + command_args="-S" + su_needed=true +elif [ "$command" = "provides" ]; then + command="pacman" + command_args="-F" +elif [ "$command" = "config" ]; then + command="nano" + command_args="/etc/pacman.conf" + su_needed=true +else + echo "Invalid command: \"$command\"" + echo + echo "Usage: pman [args...]" + echo "Available commands:" + echo " search - pacman -Ss | search packages" + echo " update - pacman -Sy | updates the repositories" + echo " upgradable - pacman -Qu | list available upgrades" + echo " upgrade - pacman -Syu | upgrades your system" + echo " provides - pacman -F | list packages that provide file" + echo " config - /etc/pacman.conf | edits pacman configuration" + exit 1 +fi + +# If sudo is needed and necessary (and installed), prepend it +if [ "$su_needed" = "true" ] && [ "$UID" != 0 ] && command -v "sudo" &>/dev/null; then + sudo $command $command_args "${@}" +else + $command $command_args "${@}" +fi