-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5587f36
Showing
5 changed files
with
361 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pac-wrapper-*-*-any.pkg.tar.zst | ||
pkg/ | ||
src/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 eatsu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Maintainer: eatsu <[email protected]> | ||
|
||
pkgname='pac-wrapper' | ||
pkgver='1.0.0' | ||
pkgrel='1' | ||
pkgdesc='A simple pacman wrapper that provides intuitive syntax similar to dnf, apt, zypper, etc.' | ||
arch=('any') | ||
url='https://github.com/eatsu/pac-wrapper' | ||
license=('MIT') | ||
depends=( | ||
'bash' | ||
'pacman' | ||
'sudo' | ||
) | ||
source=( | ||
'pac' | ||
'LICENSE' | ||
'README.md' | ||
) | ||
sha256sums=( | ||
'SKIP' | ||
'SKIP' | ||
'SKIP' | ||
) | ||
|
||
package() { | ||
cd "$srcdir" | ||
|
||
# binary | ||
install -vDm755 -t "$pkgdir/usr/bin" pac | ||
|
||
# completions | ||
# install -vDm644 completions/pac.bash "$pkgdir/usr/share/bash-completion/completions/$pkgname" | ||
# install -vDm644 completions/pac.zsh "$pkgdir/usr/share/zsh/site-functions/_$pkgname" | ||
|
||
# license | ||
install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE | ||
|
||
# doc | ||
install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Pac | ||
|
||
Pac is a simple pacman wrapper that provides intuitive syntax similar to | ||
`dnf`, `apt`, `zypper`, etc. | ||
|
||
With `pac` you don't need to memorize the non-intuitive options like | ||
`-Rs`, `-Ss`, `-Si`; you can just type `remove`, `search`, `info`, | ||
respectively. | ||
|
||
> **Note**: Pac itself is not an AUR helper, though it can wrap an AUR helper | ||
> that supports pacman's options. See [Configuration](#configuration). | ||
## Installation | ||
|
||
To install from source, run `makepkg -si`. | ||
|
||
## Usage | ||
|
||
- To upgrade installed packages, run `pac`. | ||
- To install package `foo`, run `pac install foo` or `pac in foo`. | ||
- To remove package `foo`, run `pac remove foo` or `pac rm foo`. | ||
- To show information about package `foo` (whichever installed or not, or a | ||
package group or not), run `pac info foo` or `pac if foo`. | ||
- To mark package `foo` as dependencies, run `pac mark --asdeps foo` or | ||
`pac mark -d foo`. | ||
- To remove dependencies that are no longer required by any installed package, | ||
run `pac autoremove`. | ||
- To list explicitly installed foreign packages (e.g. AUR packages), run | ||
`pac list --explicit --foreign` or `pac ls -e -f`. | ||
|
||
Run `pac --help` for more information. | ||
|
||
## Configuration | ||
|
||
By default, `pac` wraps `pacman`. To wrap another pacman-compatible program, | ||
set the environment variable `PAC_PACMAN`. | ||
|
||
For example, to wrap `paru` instead of `pacman`, add | ||
|
||
```sh | ||
export PAC_PACMAN='paru' | ||
``` | ||
|
||
to your `~/.bash_profile` (or `$ZDOTDIR/.zshenv` for Zsh) and reload your shell. | ||
|
||
## TODO | ||
|
||
- Support Tab completion for bash and zsh. | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# A simple pacman wrapper that provides intuitive syntax similar to dnf, apt, | ||
# zypper, etc. | ||
# | ||
set -ueo pipefail | ||
|
||
VERSION="1.0.0" | ||
PACMAN="${PAC_PACMAN:-"pacman"}" | ||
|
||
if [[ "$PACMAN" == "pacman" ]] && (( EUID != 0 )); then | ||
SUDO_PACMAN=("sudo" "$PACMAN") | ||
else | ||
SUDO_PACMAN=("$PACMAN") | ||
fi | ||
|
||
help() { | ||
cat << EOF | ||
Usage: | ||
pac <command> [option(s)] [...] | ||
pac [option] | ||
Commands: | ||
install, in <package(s)> Install packages and their dependencies | ||
remove, rm <package(s)> Remove packages and their dependencies | ||
autoremove, arm Remove dependencies that are no longer needed (orphans) | ||
clean Remove old packages from cache directory | ||
upgrade, up Sync databases and upgrade installed packages | ||
search, se <keyword(s)> Search package names and descriptions | ||
info, if <package(s)> Show package information | ||
files <package(s)> Show package file list | ||
owner <file(s)> Query packages that own the files | ||
mark <package(s)> Mark packages as explicitly installed | ||
list, ls List installed packages | ||
Command 'search' specific options: | ||
-i, --installed Search only installed package names and descriptions | ||
Command 'mark' specific options: | ||
-d, --asdeps Mark packages as dependencies | ||
Command 'list' specific options: | ||
-e, --explicit List packages explicitly installed | ||
-d, --deps List packages installed as dependencies | ||
-n, --native List installed packages found in sync db(s) | ||
-f, --foreign List installed packages not found in sync db(s) | ||
General options: | ||
-h, --help Print help information | ||
-V, --version Print version information | ||
-s, --status Print what pac is wrapping | ||
If no arguments are provided, 'pac upgrade' will be performed. | ||
EOF | ||
} | ||
|
||
version() { | ||
echo "pac $VERSION" | ||
} | ||
|
||
status() { | ||
cat << EOF | ||
pac is wrapping '$PACMAN'. | ||
To wrap another pacman-compatible program, set the environment variable | ||
'PAC_PACMAN'. | ||
EOF | ||
} | ||
|
||
install() { | ||
"${SUDO_PACMAN[@]}" -S "$@" | ||
} | ||
|
||
remove() { | ||
"${SUDO_PACMAN[@]}" -Rs "$@" | ||
} | ||
|
||
autoremove() { | ||
readarray -t pkgs < <("$PACMAN" -Qdtq "$@") | ||
if [[ -n "${pkgs[*]}" ]]; then | ||
"${SUDO_PACMAN[@]}" -Rs "${pkgs[@]}" | ||
else | ||
false | ||
fi | ||
} | ||
|
||
clean() { | ||
"$PACMAN" -Sc "$@" | ||
} | ||
|
||
upgrade() { | ||
"${SUDO_PACMAN[@]}" -Syu "$@" | ||
} | ||
|
||
search() { | ||
for i in "$@"; do | ||
case "$i" in | ||
-i|--installed) | ||
local installed="true" | ||
;; | ||
-*) | ||
echo "pac search: unrecognized option '$i'" | ||
exit 1 | ||
;; | ||
*) | ||
local pkgs+=("$i") | ||
;; | ||
esac | ||
done | ||
|
||
if "${installed:-"false"}"; then | ||
"$PACMAN" -Qs "${pkgs[@]}" | ||
else | ||
"$PACMAN" -Ss "${pkgs[@]}" | ||
fi | ||
} | ||
|
||
info() { | ||
for i in "$@"; do | ||
# Add newline to -g to match -i | ||
("$PACMAN" -Qg "$i" 2> /dev/null && echo) || \ | ||
("$PACMAN" -Qi "$i" 2> /dev/null) || \ | ||
("$PACMAN" -Sg "$i" 2> /dev/null && echo) || \ | ||
("$PACMAN" -Si "$i") | ||
done | ||
} | ||
|
||
owner() { | ||
"$PACMAN" -Qo "$@" | ||
} | ||
|
||
files() { | ||
"$PACMAN" -Ql "$@" | ||
} | ||
|
||
mark() { | ||
for i in "$@"; do | ||
case "$i" in | ||
-d|--asdeps) | ||
local opts+=("--asdeps") | ||
;; | ||
-*) | ||
echo "pac mark: unrecognized option '$i'" | ||
exit 1 | ||
;; | ||
*) | ||
local pkgs+=("$i") | ||
;; | ||
esac | ||
done | ||
|
||
"${SUDO_PACMAN[@]}" -D "${opts[@]:-"--asexplicit"}" "${pkgs[@]}" | ||
} | ||
|
||
list() { | ||
for i in "$@"; do | ||
case "$i" in | ||
-e|--explicit) | ||
local opts+=("--explicit") | ||
;; | ||
-d|--deps) | ||
local opts+=("--deps") | ||
;; | ||
-n|--native) | ||
local opts+=("--native") | ||
;; | ||
-f|--foreign) | ||
local opts+=("--foreign") | ||
;; | ||
-*) | ||
echo "pac list: unrecognized option '$i'" | ||
exit 1 | ||
;; | ||
*) | ||
local pkgs+=("$i") | ||
;; | ||
esac | ||
done | ||
|
||
"$PACMAN" -Q "${opts[@]}" "${pkgs[@]}" | ||
} | ||
|
||
main() { | ||
case "${1:-}" in | ||
""|up|upgrade) | ||
shift || true | ||
upgrade "$@" | ||
;; | ||
in|install) | ||
shift | ||
install "$@" | ||
;; | ||
rm|remove) | ||
shift | ||
remove "$@" | ||
;; | ||
arm|autoremove) | ||
shift | ||
autoremove "$@" | ||
;; | ||
clean) | ||
shift | ||
clean "$@" | ||
;; | ||
se|search) | ||
shift | ||
search "$@" | ||
;; | ||
if|info) | ||
shift | ||
info "$@" | ||
;; | ||
owner) | ||
shift | ||
owner "$@" | ||
;; | ||
files) | ||
shift | ||
files "$@" | ||
;; | ||
mark) | ||
shift | ||
mark "$@" | ||
;; | ||
ls|list) | ||
shift | ||
list "$@" | ||
;; | ||
-h|--help) | ||
help | ||
;; | ||
-V|--version) | ||
version | ||
;; | ||
-s|--status) | ||
status | ||
;; | ||
*) | ||
"$PACMAN" "$@" | ||
;; | ||
esac | ||
} | ||
|
||
main "$@" |