2023-04-03 11:51:58 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Store the first command line argument in the variable "command" and shift the rest
|
2023-05-06 03:18:02 +02:00
|
|
|
command_args="$1"
|
2023-04-03 11:51:58 +02:00
|
|
|
shift
|
2023-05-06 03:34:31 +02:00
|
|
|
command=""
|
|
|
|
more_arguments=false
|
|
|
|
su_needed=false
|
|
|
|
|
|
|
|
# Check if yay (aur)
|
|
|
|
if [ "$command_args" = "yay" ]; then
|
|
|
|
command="yay"
|
|
|
|
command_args="$1"
|
|
|
|
shift
|
|
|
|
more_arguments=true
|
|
|
|
# Check if config
|
|
|
|
elif [ "$command_args" = "config" ]; then
|
|
|
|
command="nano"
|
|
|
|
command_args="/etc/pacman.conf"
|
|
|
|
su_needed=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If command is empty, command is pacman
|
|
|
|
if [ "$command" = "" ]; then
|
|
|
|
command="pacman"
|
|
|
|
more_arguments=true
|
|
|
|
fi
|
2023-04-03 11:51:58 +02:00
|
|
|
|
2023-05-06 03:18:02 +02:00
|
|
|
# Evaluate the command arguments
|
|
|
|
if [ "$command_args" = "search" ]; then
|
2023-04-03 11:51:58 +02:00
|
|
|
command_args="-Ss"
|
2023-05-06 03:18:02 +02:00
|
|
|
elif [ "$command_args" = "update" ]; then
|
2023-04-03 11:51:58 +02:00
|
|
|
command_args="-Sy"
|
2023-05-06 03:34:31 +02:00
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
2023-05-06 03:18:02 +02:00
|
|
|
elif [ "$command_args" = "upgradable" ]; then
|
2023-04-03 11:51:58 +02:00
|
|
|
command_args="-Qu"
|
2023-05-06 03:18:02 +02:00
|
|
|
elif [ "$command_args" = "upgrade" ]; then
|
2023-04-03 11:51:58 +02:00
|
|
|
command_args="-Syu"
|
2023-05-06 03:34:31 +02:00
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
2023-05-06 03:18:02 +02:00
|
|
|
elif [ "$command_args" = "install" ]; then
|
2023-04-03 11:51:58 +02:00
|
|
|
command_args="-S"
|
2023-05-06 03:34:31 +02:00
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
2023-05-06 03:18:02 +02:00
|
|
|
elif [ "$command_args" = "provides" ]; then
|
2023-04-03 11:51:58 +02:00
|
|
|
command_args="-F"
|
2023-05-06 03:34:31 +02:00
|
|
|
elif [ "$more_arguments" = "true" ]; then
|
|
|
|
echo "Invalid command: \"$command $command_args\""
|
2023-04-03 11:51:58 +02:00
|
|
|
echo
|
|
|
|
echo "Usage: pman <command> [args...]"
|
|
|
|
echo "Available commands:"
|
2023-05-06 03:34:31 +02:00
|
|
|
echo " yay (aur) - yay | invoke yay "
|
|
|
|
echo " (aur packages - all the normal operations except config are available)"
|
|
|
|
echo " aur (yay) - yay | same as \"yay\""
|
2023-04-03 11:51:58 +02:00
|
|
|
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
|