-
Notifications
You must be signed in to change notification settings - Fork 19
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
Elsie19
wants to merge
46
commits into
master
Choose a base branch
from
nushell
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
dcd1878
Yippee
Elsie19 acabb0c
Muah
Elsie19 10eb4ad
Le mua
Elsie19 5ae5b62
Add flatpak remote
Elsie19 3565cdf
Add apt
Elsie19 efcb1fc
Snap starting
Elsie19 ae515b7
Make snap work
Elsie19 94272de
Oop
Elsie19 cc1b23d
Reorganize
Elsie19 b8c1ae0
Add install functionality
Elsie19 106c8f4
Add cleanup
Elsie19 9b4325a
Add remove
Elsie19 72f0590
Add messages explaining why nothing is found
Elsie19 19c7a21
Sparklez
Elsie19 d722fbf
Add multi select
Elsie19 dae443b
Fix stuff
Elsie19 15d60f7
Fix more stuff?
Elsie19 0aef031
Lets try this
Elsie19 43e6af1
Show message
Elsie19 4f59720
Shmorp error line
Elsie19 5d53fc0
Exit code?
Elsie19 4ae5cb9
Nah
Elsie19 35df8df
we're back
Elsie19 b4c982b
fix(output): print all selections at once
Elsie19 af2439b
fix(output): replace gradient with bold
Elsie19 34c774b
fix(cleanup): add missing base command
Elsie19 a7e3e3c
add: update subcommand
Elsie19 eca984c
rm: old rpk
Elsie19 66caa36
Merge rpk2
Elsie19 a5bb6f5
fix: add back license file
Elsie19 d11eb2f
Add back PO files for prep
Elsie19 7929d51
Add back readme PO notice
Elsie19 dc910e3
Add back installing PO files
Elsie19 6bc36d0
Merge branch 'master' into nushell
Elsie19 f9d0e38
Finalize
Elsie19 fc6aa70
Add pot file
Elsie19 fac4aba
Use some current translations
Elsie19 0203623
Generate line numbers as well
Elsie19 f0b9fb0
Add python brace formatting specifier
Elsie19 e0c01a3
Fix some PO files
Elsie19 0cc3ce6
Remove unused strings
Elsie19 e8db8be
Easier instructions
Elsie19 668a9ae
This doesnt need to be translated
Elsie19 428422a
Fix plugins in scripts
Elsie19 90edb60
Return empty table on empty input
Elsie19 e9993a7
Fix lord Oren's complaints
Elsie19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 @@ | ||
# Developing | ||
|
||
## i18n | ||
Run `xnutext rhino-pkg **/*.nu -o po/rhino-pkg.pot` after adding new translatable text. |
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
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
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,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. |
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,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)} | ||
} | ||
} |
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 @@ | ||
export module screen.nu | ||
export module cmd.nu | ||
export module search.nu |
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,5 @@ | ||
# Clear screen with tput | ||
export def clearscr [] { | ||
^tput cuu 1 | ||
^tput el | ||
} |
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,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 | ||
} |
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,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 { | ||
[] | ||
} | ||
} | ||
|
||
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 | ||
} | ||
} | ||
} |
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,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 | ||
} | ||
} | ||
} |
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,5 @@ | ||
# Apparently this is how it works | ||
export module pacstall.nu | ||
export module flatpak.nu | ||
export module apt.nu | ||
export module snap.nu |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Search has also been broken the entire time.