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

feat: rewrite in nushell #52

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
dcd1878
Yippee
Elsie19 Sep 29, 2024
acabb0c
Muah
Elsie19 Sep 29, 2024
10eb4ad
Le mua
Elsie19 Oct 16, 2024
5ae5b62
Add flatpak remote
Elsie19 Oct 16, 2024
3565cdf
Add apt
Elsie19 Oct 16, 2024
efcb1fc
Snap starting
Elsie19 Oct 28, 2024
ae515b7
Make snap work
Elsie19 Nov 1, 2024
94272de
Oop
Elsie19 Nov 1, 2024
cc1b23d
Reorganize
Elsie19 Nov 1, 2024
b8c1ae0
Add install functionality
Elsie19 Nov 1, 2024
106c8f4
Add cleanup
Elsie19 Nov 1, 2024
9b4325a
Add remove
Elsie19 Nov 2, 2024
72f0590
Add messages explaining why nothing is found
Elsie19 Nov 2, 2024
19c7a21
Sparklez
Elsie19 Nov 2, 2024
d722fbf
Add multi select
Elsie19 Nov 2, 2024
dae443b
Fix stuff
Elsie19 Nov 2, 2024
15d60f7
Fix more stuff?
Elsie19 Nov 2, 2024
0aef031
Lets try this
Elsie19 Nov 2, 2024
43e6af1
Show message
Elsie19 Nov 2, 2024
4f59720
Shmorp error line
Elsie19 Nov 2, 2024
5d53fc0
Exit code?
Elsie19 Nov 2, 2024
4ae5cb9
Nah
Elsie19 Nov 2, 2024
35df8df
we're back
Elsie19 Nov 2, 2024
b4c982b
fix(output): print all selections at once
Elsie19 Nov 3, 2024
af2439b
fix(output): replace gradient with bold
Elsie19 Nov 3, 2024
34c774b
fix(cleanup): add missing base command
Elsie19 Nov 3, 2024
a7e3e3c
add: update subcommand
Elsie19 Nov 7, 2024
eca984c
rm: old rpk
Elsie19 Dec 5, 2024
66caa36
Merge rpk2
Elsie19 Dec 5, 2024
a5bb6f5
fix: add back license file
Elsie19 Dec 5, 2024
d11eb2f
Add back PO files for prep
Elsie19 Dec 31, 2024
7929d51
Add back readme PO notice
Elsie19 Dec 31, 2024
dc910e3
Add back installing PO files
Elsie19 Dec 31, 2024
6bc36d0
Merge branch 'master' into nushell
Elsie19 Dec 31, 2024
f9d0e38
Finalize
Elsie19 Jan 1, 2025
fc6aa70
Add pot file
Elsie19 Jan 1, 2025
fac4aba
Use some current translations
Elsie19 Jan 1, 2025
0203623
Generate line numbers as well
Elsie19 Jan 1, 2025
f0b9fb0
Add python brace formatting specifier
Elsie19 Jan 1, 2025
e0c01a3
Fix some PO files
Elsie19 Jan 1, 2025
0cc3ce6
Remove unused strings
Elsie19 Jan 1, 2025
e8db8be
Easier instructions
Elsie19 Jan 1, 2025
668a9ae
This doesnt need to be translated
Elsie19 Jan 3, 2025
428422a
Fix plugins in scripts
Elsie19 Jan 5, 2025
90edb60
Return empty table on empty input
Elsie19 Jan 9, 2025
e9993a7
Fix lord Oren's complaints
Elsie19 Jan 9, 2025
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
4 changes: 4 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Developing

## i18n
Run `xnutext rhino-pkg **/*.nu -o po/rhino-pkg.pot` after adding new translatable text.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ all: install

install:
mapfile -t linguas <po/LINGUAS && for i in "$${linguas[@]}"; do mkdir -p $(DESTDIR)/usr/share/locale/"$${i}"/LC_MESSAGES/ && msgfmt -o $(DESTDIR)/usr/share/locale/"$${i}"/LC_MESSAGES/rhino-pkg.mo po/"$${i}".po; done
mkdir -pv $(DESTDIR)/usr/share/rhino-pkg/
cp -rv modules/ $(DESTDIR)/usr/share/rhino-pkg/
install -Dm755 rhino-pkg -t $(DESTDIR)/usr/bin/
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ A package manager wrapper for Pacstall, APT, Flatpak and snap.

### Usage
```
USAGE: rhino-pkg [function] {flag} <input>
USAGE: rhino-pkg [function] {flag} <input>

functions:
install: Install package(s) - Prompts user to respond with
install: Install package(s) - Prompts user to respond with
the number(s) associated with the desired package(s).

remove: Uninstall package(s) - Prompts user to respond with
the number(s) associated with the desired package(s).

search: Search for package(s) - Does not have a second prompt.

update: Updates all packages accessible to the wrapper - does
not accept <input>, instead use install to update
not accept <input>, instead use install to update
individual packages. Has a confirmation prompt.

cleanup: Attempts to repair broken dependencies and remove any
unused packages. Does not accept <input>, but has
unused packages. Does not accept <input>, but has
a confirmation prompt.

flags:
flags:
--help/-h: Display this page
--description/-d: By default, rhino-pkg will only display packages
that contain <input> within their name. Use this flag to increase

--description/-d: By default, rhino-pkg will only display packages
that contain <input> within their name. Use this flag to increase
range and display packages with <input> in their description.

-y: Makes functions with confirmation prompts run promptless.
input:

input:
Provide a package name or description.

Example execution:
Expand Down
5 changes: 5 additions & 0 deletions docs/adding_new_plug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Adding new package manager plug

1. Add a color to `modules/lib/cmd.nu`.
2. Add an entry to `modules/pluggables/mod.nu`.
2. Copy one of the files from `modules/pluggables/` and add it.
135 changes: 135 additions & 0 deletions modules/lib/cmd.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
export def exists [cmd: string] : nothing -> bool {
((which $cmd | length) > 0)
}

# Return color based off of package manager
export def print-color [type: string] {
match $type {
"pacstall" => (ansi yellow_bold)
"apt" => (ansi green_bold)
"flatpak" => (ansi cyan_bold)
"snap" => (ansi red_bold)
_ => (ansi grey_bold)
}
}

export def prompt [ask: string, pkgs: list] : nothing -> table {
let input = (input $"($ask) [0-(($pkgs | length) - 1)]: ")
if ($input | is-empty) {
[($pkgs | enumerate).0.item]
} else {
let parsed = ($input
| split row ' '
| find --regex "[0-9]+" --regex "^[0-9]+"
| into int
| filter {|key| $key in 0..<($pkgs | length)}
)
if ($parsed | is-empty) {
tprint -e "No valid inputs given"
exit 1
}
$pkgs
| enumerate
| where index in $parsed
| flatten
}
}

export def install-pkg [
pkg: record,
promptless: bool
] {
match $pkg.provider {
"pacstall" => {
if $promptless {
^pacstall -PI $"($pkg.pkg)@($pkg.repo)"
} else {
^pacstall -I $"($pkg.pkg)@($pkg.repo)"
}
}
"apt" => {
if $promptless {
^sudo apt-get install $pkg.pkg -y
} else {
^sudo apt-get install $pkg.pkg
}
}
"flatpak" => {
if $promptless {
^flatpak install $pkg.remote $pkg.pkg -y
} else {
^flatpak install $pkg.remote $pkg.pkg
}
}
# So snap is weird because some packages need classic installation
# ref: [https://github.com/rhino-linux/rhino-pkg/issues/46].
# But on the plus side it doesn't have the ability for -y.
"snap" => {
if ($pkg.Notes == "classic") {
^sudo snap install --classic $pkg.pkg
} else {
^sudo snap install $pkg.pkg
}
}
}
}

export def remove-pkg [
pkg: record,
promptless: bool
] {
match $pkg.provider {
"pacstall" => {
if $promptless {
^pacstall -PR $pkg.pkg
} else {
^pacstall -R $pkg.pkg
}
}
"apt" => {
if $promptless {
^sudo apt-get remove $pkg.pkg -y
} else {
^sudo apt-get remove $pkg.pkg
}
}
"flatpak" => {
if $promptless {
^flatpak remove $pkg.pkg -y
} else {
^flatpak remove $pkg.pkg
}
}
"snap" => {
^sudo snap remove $pkg.pkg --purge
}
}
}

export def cleanup-pkg [promptless: bool] {
if $promptless {
if (exists "apt") {
^sudo apt-get --fix-broken install
^sudo apt-get apt-remove -y
}
if (exists "flatpak") {
^sudo flatpak repair
^sudo flatpak uninstall --unused -y
}
} else {
if (exists "apt") {
^sudo apt-get --fix-broken install
^sudo apt-get apt-remove
}
if (exists "flatpak") {
^sudo flatpak repair
^sudo flatpak uninstall --unused
}
}
if (exists "snap") {
^snap list --all
| detect columns
| where Notes =~ "disabled"
| each {|pkg| ^sudo snap remove $pkg.Name --revision=($pkg.Version)}
}
}
3 changes: 3 additions & 0 deletions modules/lib/mod.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export module screen.nu
export module cmd.nu
export module search.nu
5 changes: 5 additions & 0 deletions modules/lib/screen.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Clear screen with tput
export def clearscr [] {
^tput cuu 1
^tput el
}
53 changes: 53 additions & 0 deletions modules/lib/search.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use "/usr/share/rhino-pkg/modules/lib/screen.nu" [clearscr]
use "/usr/share/rhino-pkg/modules/lib/cmd.nu" [print-color]

export def search-pkgs [
description: bool
rest: string
] : nothing -> table {
use "/usr/share/rhino-pkg/modules/pluggables/" [pacstall flatpak apt snap]
tprint "Searching Pacstall…"
let pac_results = (pacstall search $rest $description)
clearscr
tprint "Searching flatpak…"
let flatpak_results = (flatpak search $rest $description)
clearscr
tprint "Searching apt…"
let apt_results = (apt search $rest $description)
tprint "Searching snap…"
let snap_results = (snap search $rest $description)
clearscr
let total = $snap_results | append $flatpak_results | append $apt_results | append $pac_results
mut idx = 0
for bla in $total {
let le_color = (print-color $bla.provider)
print $"[($le_color)($idx)(ansi reset)]: ($bla.pkg) \(($le_color)($bla.provider)(ansi reset)\)"
$idx += 1
}
# Just because someone else might need the table.
return $total
}

export def search-local-pkgs [search: string] : nothing -> table {
use "/usr/share/rhino-pkg/modules/pluggables/" [pacstall flatpak apt snap]
tprint "Searching Pacstall…"
let pac_results = (pacstall list-installed $search)
clearscr
print "Searching flatpak…"
let flatpak_results = (flatpak list-installed $search)
clearscr
tprint "Searching apt…"
let apt_results = (apt list-installed $search)
tprint "Searching snap…"
let snap_results = (snap list-installed $search)
clearscr
let total = $snap_results | append $flatpak_results | append $apt_results | append $pac_results
mut idx = 0
for bla in $total {
let le_color = (print-color $bla.provider)
print $"[($le_color)($idx)(ansi reset)]: ($bla.pkg) ~ (ansi defb)($bla.version)(ansi reset) \(($le_color)($bla.provider)(ansi reset)\)"
$idx += 1
}
# Just because someone else might need the table.
return $total
}
42 changes: 42 additions & 0 deletions modules/pluggables/apt.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use "/usr/share/rhino-pkg/modules/lib/cmd.nu" [exists]

export def list-installed [search: string] {
if (exists "aptitude") {
^aptitude search $"~i($search) !?section\(Pacstall\)" -F '%p|%v'
| lines
| parse "{pkg}|{version}"
| insert provider "apt"
}
}

export def search [input: string, description: bool] : nothing -> table {
if (exists "aptitude") {
if $description {
# We are searching for something in description
^aptitude search --quiet --disable-columns $"?name\(($input)\) | ?description\(($input)\) ?architecture\(native\) !?section\(Pacstall\)" -F "%p|%d"
| lines
| parse "{pkg}|{desc}"
| insert provider 'apt'
} else {
^aptitude search --quiet --disable-columns $"?name\(($input)\) ?architecture\(native\) !?section\(Pacstall\)" -F "%p"
| lines
| parse "{pkg}"
| insert desc ''
| insert provider 'apt'
}
} else {
[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

export def upgrade [promptless: bool] {
if (exists "apt") {
if $promptless {
^sudo apt update -y
^sudo apt upgrade -y
} else {
^sudo apt update
^sudo apt upgrade
}
}
}
39 changes: 39 additions & 0 deletions modules/pluggables/flatpak.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use "/usr/share/rhino-pkg/modules/lib/cmd.nu" [exists]

export def list-installed [search: string] {
if (exists "flatpak") {
^flatpak list --columns=application:f,version:f --app
| lines
| uniq
| parse "{pkg}\t{version}"
| where pkg =~ $search
| insert provider "flatpak"
}
}

export def search [input: string, description: bool] : nothing -> table {
# Description here is a dummy flag, because flatpak searches by both name and description with no way
# to change that afaik.
if (exists "flatpak") {
^flatpak search $input --columns=application:f,remotes:f
| lines
| parse -r '^([\w.-]+)\s+(\w+)$'
| rename pkg remote
| insert provider 'flatpak'
| merge (^flatpak search $input --columns=description:f
| lines
| wrap 'desc')
} else {
[]
}
}

export def upgrade [promptless: bool] {
if (exists "flatpak") {
if $promptless {
^flatpak update -y
} else {
^flatpak update
}
}
}
5 changes: 5 additions & 0 deletions modules/pluggables/mod.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Apparently this is how it works
export module pacstall.nu
export module flatpak.nu
export module apt.nu
export module snap.nu
Loading