Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a Pacman package #1

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pkgname=dpw
pkgver=1.1.0
pkgrel=1
pkgdesc='Declarative Pacman Wrapper'
arch=(any)
optdepends=(
'paru: recommended pacman wrapper'
'aura: pacman wrapper'
'aurman: pacman wrapper'
'pacaur: pacman wrapper'
'pikaur: pacman wrapper'
'yay: pacman wrapper'
)
license=(GPL-3.0-or-later)
source=(dpw dpw.fish)
sha256sums=(
'4ad6164db071db5284677a40b896a50a7c7799ca4c5188366ffe210ed3423024'
'c2b828519653d3f2280d4904d7ad8924d2671986c9ad33af17ff60fba83522a1'
)

package() {
mkdir -p "${pkgdir}/usr/bin"
cp "${srcdir}/dpw" "${pkgdir}/usr/bin/dpw"
chmod +x "${pkgdir}/usr/bin/dpw"

# Add fish completions if fish shell is installed
if [ -x "$(command -v fish)" ]; then
if [ -d "/usr/share/fish/vendor_completions.d" ]; then
mkdir -p "/usr/share/fish/vendor_completions.d"
fi

sudo cp "${srcdir}/dpw.fish" "/usr/share/fish/vendor_completions.d/dpw.fish"
fi
}
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ kitty
nautilus-open-any-terminal # kitty
```

Uses `paru` by default, but it can be easily changed by modifying the `PACMAN` variable.

## Installation
Move the script to a place in your `PATH`.
Searches for any available `pacman` wrapper by default, but it can be easily changed by modifying the `PACMAN` environment variable.

## Usage
There are no arguments. Upon execution it removes non-declared packages, install newly declared packages and does a system upgrade.
See `dpw help`
48 changes: 44 additions & 4 deletions dpw
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
#!/bin/bash
set -e

PACMAN=paru
PKG_FILE="${HOME}/.config/dpw/packages.ini"

# Edit packages.ini
if [ "${1}" = "edit" ]; then
${EDITOR} "${PKG_FILE}"
# Check if PACMAN is not set and find an available helper
AUR_HELPERS=("pacaur" "pikaur" "yay" "aura" "paru" "aurman")
if [ -z "${PACMAN}" ]; then
for HELPER in "${AUR_HELPERS[@]}"; do
if command -v "$HELPER" > /dev/null 2>&1; then
PACMAN="$HELPER"
break
fi
done

if [ -z "${PACMAN}" ]; then
printf "\033[1m::\033[0m No available AUR helper found."
exit 1
fi
fi

# Show help menu
if [ "${1}" = "help" ]; then
printf "\033[1m:: \033[1;31mdpw\033[0m - Executes the program normally, using the existing packages.ini or creating a new one if it doesn't exist yet.\n"
printf "\033[1m:: \033[1;31mdpw edit\033[0m - Opens the packages.ini file in the user's selected editor (defined via the EDITOR variable).\n"
printf "\033[1m:: \033[1;31mdpw update\033[0m - Overwrites the current contents of the package.ini file with the currently installed package. Useful after using pacman or paru directly to install new packages.\n"
printf "\033[1m:: \033[1;31mdpw help\033[0m - Shows this menu.\n"
exit
fi

Expand All @@ -27,6 +45,28 @@ if [ ! -e "${PKG_FILE}" ]; then
done
fi

# Edit packages.ini
if [ "${1}" = "edit" ]; then
${EDITOR} "${PKG_FILE}"
exit
fi

# Update packages.ini
if [ "${1}" = "update" ]; then
while true; do
printf "\033[1m::\033[0m Do you wish to update the currently existing packages.ini [y/N]? "
read -r YN
case ${YN:-N} in
[Yy]*)
"${PACMAN}" --query --explicit --quiet > "${PKG_FILE}"
break;;
[Nn]*)
exit;;
esac
done
fi


# Calculate changes
function diff { comm -23 <(echo -n "$1") <(echo -n "$2"); }

Expand Down
5 changes: 5 additions & 0 deletions dpw.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set -l dpw_commands help edit update

complete -f -c dpw -n "not __fish_seen_subcommand_from $dpw_commands" -a help -d "Show the help menu"
complete -f -c dpw -n "not __fish_seen_subcommand_from $dpw_commands" -a edit -d "Open the packages.ini file in the user's selected editor [defined in the EDITOR variable]."
complete -f -c dpw -n "not __fish_seen_subcommand_from $dpw_commands" -a update -d "Overwrite the current contents of the package.ini file with the currently installed packages."