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)
|
2023-05-06 03:37:59 +02:00
|
|
|
if [ "$command_args" = "yay" ] || [ "$command_args" = "aur" ]; then
|
2023-05-06 03:34:31 +02:00
|
|
|
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-10-28 21:58:27 +02:00
|
|
|
elif [ "$command_args" = "provides" ]; then
|
|
|
|
command_args="-F"
|
2023-10-28 22:03:35 +02:00
|
|
|
elif [ "$command_args" = "installed" ]; then
|
|
|
|
command_args="-Q"
|
2023-10-28 21:58:27 +02:00
|
|
|
elif [ "$command_args" = "install" ]; then
|
|
|
|
command_args="-S"
|
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
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-15 08:11:05 +02:00
|
|
|
elif [ "$command_args" = "remove" ]; then
|
|
|
|
command_args="-Rs"
|
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
|
|
|
elif [ "$command_args" = "purge" ]; then
|
|
|
|
command_args="-Rns"
|
|
|
|
if [ "$command" = "pacman" ]; then
|
|
|
|
su_needed=true
|
|
|
|
fi
|
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"
|
2023-10-28 21:58:27 +02:00
|
|
|
echo " provides - pacman -F | list packages that provide file"
|
2023-10-28 22:03:35 +02:00
|
|
|
echo " installed - pacman -Q | list installed packages"
|
2023-05-15 08:11:05 +02:00
|
|
|
echo " install - pacman -S | install packages"
|
2023-04-03 11:51:58 +02:00
|
|
|
echo " update - pacman -Sy | updates the repositories"
|
|
|
|
echo " upgradable - pacman -Qu | list available upgrades"
|
|
|
|
echo " upgrade - pacman -Syu | upgrades your system"
|
2023-05-15 08:11:05 +02:00
|
|
|
echo " remove - pacman -Rs | remove packages & dependencies"
|
|
|
|
echo " purge - pacman -Rns | remove packages, dependencies & conf"
|
2023-04-03 11:51:58 +02:00
|
|
|
echo " config - /etc/pacman.conf | edits pacman configuration"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-10-28 22:00:06 +02:00
|
|
|
# If sudo is needed and necessary (and installed), prepend it, if not installed throw error
|
|
|
|
if [ "$su_needed" = "true" ] && [ "$UID" != 0 ]; then
|
|
|
|
if command -v "sudo" &>/dev/null; then
|
2024-06-10 06:47:32 +02:00
|
|
|
command="sudo $command"
|
2023-10-28 22:00:06 +02:00
|
|
|
else
|
|
|
|
echo "sudo command needed but not found" > /dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-04-03 11:51:58 +02:00
|
|
|
fi
|
2024-06-10 06:47:32 +02:00
|
|
|
|
|
|
|
# Execute the command
|
|
|
|
$command $command_args "${@}"
|