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

rewrite: switch to nushell #38

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1cda0de
Update rhino-pkg
wren54 Dec 3, 2023
5898a7c
Add files via upload
wren54 Dec 3, 2023
d720a23
Update rhino-pkg
wren54 Dec 3, 2023
3f552de
Update rhino-pkg
wren54 Dec 3, 2023
7216fc2
Update rhino-pkg
wren54 Dec 3, 2023
88c877b
Update rhino-pkg
wren54 Dec 3, 2023
744489a
updated with color
wren54 Dec 4, 2023
f1dd2b7
Update rhino-pkg
wren54 Dec 5, 2023
91bcca1
Add files via upload
wren54 Dec 5, 2023
609bb14
Update rhino-pkg
wren54 Dec 5, 2023
32fecc5
Update rhino-pkg
wren54 Dec 5, 2023
1c723c8
Add files via upload
wren54 Dec 5, 2023
3026420
Update rhino-pkg
wren54 Dec 6, 2023
97cec04
Add translations from old rhino-pkg
wren54 Dec 11, 2023
dad7255
Update rhino-pkg
wren54 Dec 11, 2023
e88823f
Update rhino-pkg
wren54 Dec 11, 2023
43e4c4e
Update rhino-pkg
wren54 Dec 21, 2023
44b47fe
split rhino-pkg into parts
wren54 Jan 7, 2024
4480cbd
Add files via upload
wren54 Jan 7, 2024
64dcd19
rhinu final update?
wren54 May 6, 2024
74d5ed5
Update Makefile
wren54 May 7, 2024
0176dd5
Update Makefile
wren54 May 7, 2024
d083b01
Update Makefile
wren54 May 7, 2024
a8109cc
Add files via upload
wren54 May 7, 2024
8f2dc4c
Delete translation_tomls directory
wren54 May 7, 2024
444cbe5
Update Makefile
wren54 May 7, 2024
d73d6bd
Update Makefile
wren54 May 7, 2024
dd87e13
Update Makefile
wren54 May 7, 2024
aab3de3
Update Makefile
wren54 May 7, 2024
1562460
Update get-install-dir.nu
wren54 May 7, 2024
d295844
Update get-install-dir.nu
wren54 May 7, 2024
84cc428
Update get-install-dir.nu
wren54 May 7, 2024
f6d2e96
Update get-install-dir.nu
wren54 May 7, 2024
06b9f03
Update get-install-dir.nu
wren54 May 7, 2024
9b30850
Update raw-install-dir.nu
wren54 May 7, 2024
9f6c251
Update rhino-pkg
wren54 May 9, 2024
3ed360d
Update rhino-pkg
wren54 May 10, 2024
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
23 changes: 20 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
all: install

install:
for i in po/*.po; do lang="$$(basename "$$i" .po)" && sudo mkdir -p $(DESTDIR)/usr/share/locale/"$$lang"/LC_MESSAGES/ && sudo msgfmt -o $(DESTDIR)/usr/share/locale/"$$lang"/LC_MESSAGES/rhino-pkg.mo po/"$$lang".po ; done
sudo install -Dm755 rhino-pkg -t $(DESTDIR)/usr/bin/
# This checks to make sure that DESTDIR is defined before initiation the install. \
if it is not, it informs the user they must define it and exits with an error code.
install::
ifndef DESTDIR
@echo "There was no destination given for the install. Please rerun while setting the variable DESTDIR in the command line."
exit 1
endif

# Actually makes rhino-pkg, provided that DESTDIR is defined
install::
mkdir -p $(DESTDIR)/usr/bin
mkdir -p $(DESTDIR)/usr/share/rhino-pkg/
# Copies translation-tomls recursively.
cp -r ./translation-tomls $(DESTDIR)/usr/share/rhino-pkg
# Copies over rhino-pkg's nu-files
cp -r ./nu-files $(DESTDIR)/usr/share/rhino-pkg
# Sets up the usr/bin directory and symlinks the rhino-pkg executable into it as rhino-pkg and rpk
ln -sf /usr/share/rhino-pkg/nu-files/rhino-pkg $(DESTDIR)/usr/bin/rhino-pkg
ln -sf /usr/share/rhino-pkg/nu-files/rhino-pkg $(DESTDIR)/usr/bin/rpk
chmod -R 755 $(DESTDIR)/usr/
9 changes: 9 additions & 0 deletions nu-files/commands/mod.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# As of nushell 0.89.0, for directory modules,
# all exported nu files must be listed in the mod.nu file as exports
export module rpk-cleanup.nu
export module rpk-install-or-remove.nu
export module rpk-search.nu
export module rpk-sync.nu
export module rpk-update.nu

def main [] -> {}
25 changes: 25 additions & 0 deletions nu-files/commands/rpk-cleanup.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export def main [promptless: bool = false] {
if (cmd-exist 'nala') {
^sudo nala install --fix-broken
if $promptless {
^sudo nala autoremove -y
} else {
^sudo nala autoremove
}
} else {
^sudo apt --fix-broken install
if $promptless { ^sudo apt auto-remove -y } else { ^sudo apt auto-remove }
}
if (cmd-exist 'flatpak') {
^sudo flatpak repair
if $promptless { ^sudo flatpak uninstall --unused -y } else { ^sudo flatpak uninstall --unused }
}
if (cmd-exist 'snap') {
let snaps = (^snap list --all | detect columns)
for $pkg in $snaps {
if ($pkg.Notes) =~ "disabled" {
^sudo snap remove $pkg.Name --revision=$pkg.Rev
}
}
}
}
49 changes: 49 additions & 0 deletions nu-files/commands/rpk-install-or-remove.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use "../helper-scripts/" [user-package-selection, translation-dir-path]

export def main [install: bool = true] {
let input: table = $in
let user_input_ints = user-package-selection $input (if $install {"install"} else { "remove" })

$user_input_ints | each { |index|
let pkg = ($input | get $index | get package)
let provider = ($input | get $index | get provider)


#print $"Selecting '(ansi purple_bold)($pkg)(ansi reset)' from package manager '(ansi purple_bold)($provider)(ansi reset)'"

if $install {
translation-dir-path | translate install-select {package: $pkg, manager: $provider, color: "magenta" } | print
} else {
translation-dir-path | translate remove-select {package: $pkg, manager: $provider, color: "magenta" } | print
}


let r_u_sure = translation-dir-path| translate ask.sure
let sure = (input --numchar 1 $"($r_u_sure) ")

let no: bool = (($sure != "Y") and ($sure != "y"))
# let sure = (input $"Are you sure? \((ansi green_bold)y(ansi reset)/(ansi red_bold)N(ansi reset)\) ")
if $no {
translation-dir-path | translate skipping {package: $pkg, manager: $provider, color: "magenta"} | print
} else {

if $install {
match ($provider) {
"pacstall" => (^pacstall -I $pkg),
"snap" => (^sudo snap install $pkg),
"apt" => (^sudo apt install $pkg -y),
"flatpak" => (^sudo flatpak install $pkg -y),
"zap" => (^sudo zap install $pkg -q)
}
} else {
match ($provider) {
"pacstall" => (^pacstall -R $pkg),
"snap" => (^sudo snap remove $pkg),
"apt" => (^sudo apt remove $pkg -y),
"flatpak" => (^sudo flatpak remove $pkg -y),
"zap" => (^sudo zap remove $pkg -q)
}
}
}
}
}
164 changes: 164 additions & 0 deletions nu-files/commands/rpk-search.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
use '../helper-scripts/' [cmd-exist, fetch-version, single-line-print, add-whitespace-until-string-length, translation-dir-path]

const VERSION_SEARCH_WARN = 200;

def search-apt [input: string, desc: bool] -> table {
if (cmd-exist 'apt-cache') {
let first_table = if $desc == true {
(^apt-cache search $input | lines | parse "{package} - {description}" | insert provider 'apt')
} else {
(^apt-cache search --names-only $input | lines | parse "{package} - {description}" | insert provider 'apt')
}
$first_table
} else { return [] }
}

def search-pacstall [input: string] -> table {
if (cmd-exist 'pacstall') {
let pacstall = do { ^pacstall -S $input } | complete
return ($pacstall.stdout | ansi strip | lines | parse "{package} @ {repo}" | reject repo | insert description '' | insert provider 'pacstall')
# if ($result | is-empty) {
# print -n $"\e[A\e[K"
# }
} else { return [] }
}

def search-flatpak [input: string, desc: bool] -> table {
if (cmd-exist 'flatpak') {
if $desc == true {
let flatpak = (^flatpak search $input --columns=application | lines | wrap 'package' | insert provider 'flatpak' | merge (^flatpak search $input --columns=description | lines | wrap 'description'))
if ($flatpak.package.0 == "No matches found") { return [] } else { return $flatpak }
} else {
let flatpak = (^flatpak search $input --columns=application | lines | wrap 'package' | insert provider 'flatpak' | insert description '')
if ($flatpak.package.0 == "No matches found") { return [] } else { return $flatpak }
}
} else {print 'flatpak not installed'; return [] }
}

def search-snap [input: string] -> table {
if (cmd-exist 'snap') {
return (^snap search $input | detect columns | get Name | wrap 'package' | insert description '' | insert provider 'snap')
} else { return [] }
}



def prune-search-table [prune_term: string] -> table {
let input_table: table = $in
let downcase_prune_term = ($prune_term |str downcase)
$input_table | filter { |row| (($row.package | into string | str downcase | str contains $downcase_prune_term) or ($row.description | into string | str downcase | str contains $downcase_prune_term))}
}

export def main [input: string, desc: bool = false, extra_prune_terms: table = []] -> table {
translation-dir-path | translate searching.apt | print
# print "Searching apt…"
let apt = (search-apt $input $desc)
print -n $"\e[A\e[K"
# print "Searching Pacstall…"
translation-dir-path | translate searching.pacstall | print
let pacstall = (search-pacstall $input)
print -n $"\e[A\e[K"
# print "Searching flatpak…"
translation-dir-path | translate searching.flatpak | print
let flatpak = (search-flatpak $input $desc)
print -n $"\e[A\e[K"
# print "Searching snap…"
translation-dir-path | translate searching.snap | print
let snap = (search-snap $input)
print -n $"\e[A\e[K"
#print $extra_prune_terms
mut results = ($apt | append $pacstall | append $flatpak | append $snap )

#additional search terms management
mut search_term: string = $input
for i in 0..<($extra_prune_terms | length ) {
let prune_term: string = ($extra_prune_terms | select $i).0
# prune the results based on other search terms
$results = ($results | prune-search-table $prune_term)
# making search terms into one string
$search_term += " "
$search_term += $prune_term
}


# print -n $"\e[A\e[K"
if ($results | is-empty) {
# print -e $"No packages found matching '($input)'!"
translation-dir-path | translate none-matching {search: $search_term, color: magenta } | print
exit 1
}
let results_len = $results | length

(translation-dir-path | translate found-matching {matches: $results_len, search: $search_term, color: magenta} ) + "\n" | print
# print $"Found packages matching '(ansi purple_bold)($input)(ansi reset)':\n"

mut skip_version_search: bool = false
if $results_len > $VERSION_SEARCH_WARN {
let prompt = $"Search resulted in over ($VERSION_SEARCH_WARN) packages. Searching whether the packages are installed may take significant time. Would you like to skip this step? \(Y/n\)"
let skip = (input --numchar 1 $"($prompt) " | str downcase)
$skip_version_search = ($skip != "n")
}
$results = ($results | insert version '')
if not $skip_version_search {
let version_table = ($results | calc-version-numbers)
$results = ($results | merge $version_table)
}
#preparation for descriptions
mut longest_package_name_length = 0
if true {
#find length of longest package name
for i in 0..<$results_len {
if (($results.package | select $i).0 | ansi strip | str length --grapheme-clusters) > $longest_package_name_length {
$longest_package_name_length = (($results.package | select $i).0 | ansi strip | str length --grapheme-clusters)
}
}
}
mut longest_version_length = 0
if not $skip_version_search {
for i in 0..<$results_len {
if (($results.version |select $i).0 | ansi strip | str length --grapheme-clusters) > $longest_version_length {
$longest_version_length = (($results.version | select $i).0 | ansi strip | str length --grapheme-clusters)
}
}
}
mut count = 0
# Loop over results
let result_max_digits: int = ($results_len | into string | str length --grapheme-clusters)
for $i in $results {
let style = match $i.provider {
"pacstall" => $"(ansi yellow_bold)",
"apt" => $"(ansi green_bold)",
"flatpak" => $"(ansi cyan_bold)",
"snap" => $"(ansi red_bold)",

_ => $"(ansi white_bold)"
}
let number_label: string = ($"[($style)($count)(ansi reset)]:" | add-whitespace-until-string-length ( $result_max_digits + 4 ))
let package_label: string = ($"($i.package)" | add-whitespace-until-string-length ($longest_package_name_length + 1) )
let version_label: string = ($i.version | add-whitespace-until-string-length ($longest_version_length + 1) )
let provider_label: string = ($"\(($style)($i.provider)(ansi reset)\)" | add-whitespace-until-string-length 11 )
if $desc {

let description = $" ($i.description)"
if ($i.description | is-empty) {
single-line-print $"($number_label)($package_label)($version_label)($provider_label)"
} else {
single-line-print $"($number_label)($package_label)($version_label)($provider_label)($description)"
}
} else {
single-line-print $"($number_label)($package_label)($version_label)($provider_label)"
}
$count += 1
}

return $results
}


def calc-version-numbers [] -> table {
let packages_table = $in
print "Searching for if any of the packages are installed."
let versions = $packages_table | par-each -k { |row| ($row.package | fetch-version $row.provider) }
print -n $"\e[A\e[K"
$versions | wrap version
}
12 changes: 12 additions & 0 deletions nu-files/commands/rpk-sync.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Functions like the sync command for pacman
# Updates all repos that can update their repos
export def main [ ] {
if (cmd-exist 'nala') {
^sudo nala update
} else {
^sudo apt update
}
if (cmd-exist 'flatpak') {
^flatpak update --appstream
}
}
32 changes: 32 additions & 0 deletions nu-files/commands/rpk-update.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export def main [promptless: bool = false] {

let r_u_sure = translation-dir-path| translate ask.upgrade
let sure: string = (input --numchar 1 $"($r_u_sure)")
# let sure = (input $"Are you sure you want to update all packages? \((ansi green_bold)y(ansi reset)/(ansi red_bold)N(ansi reset)\) ")
let no: bool = (($sure != "Y") and ($sure != "y"))
if $no {
exit 1
}

if (cmd-exist 'nala') {
if $promptless {
^sudo nala upgrade --full --no-autoremove -o Acquire::AllowReleaseInfoChange="true" -y
} else {
^sudo nala upgrade --full --no-autoremove -o Acquire::AllowReleaseInfoChange="true"
}
} else {
^sudo apt update --allow-releaseinfo-change
if $promptless { ^sudo apt upgrade -y } else { ^sudo apt upgrade }
}
if (cmd-exist 'pacstall') {
^pacstall -U
if $promptless { ^pacstall -PUp } else { ^pacstall -Up }
}
if (cmd-exist 'flatpak') {
if $promptless { ^sudo flatpak update -y } else { ^sudo flatpak update }
}
if (cmd-exist 'snap') {
^sudo snap refresh
}

}
14 changes: 14 additions & 0 deletions nu-files/helper-scripts/add-whitespace-until-string-length.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#USAGE: adds whitespace to the end of a string $in until it is $length characters long
export def main [length: int, --front (-f)] -> string {
let input: string = $in
let amount = ($length - ($input | ansi strip | str length --grapheme-clusters))
mut whitespace_string = $input
for _ in 0..<$amount {
if not $front {
$whitespace_string += " "
} else {
$whitespace_string = " " + $whitespace_string
}
}
$whitespace_string
}
4 changes: 4 additions & 0 deletions nu-files/helper-scripts/cmd-exist.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export def main [input: string] -> bool {
let stuff = (which $input)
if ($stuff | is-empty) { return false } else if ($stuff).type.0 == "external" { return true }
}
Loading