dotfiles
bugabingas dorkfiles
owned by bugabinga
package.nu: can isntall packages now
c594fb051e840ecd06191276f0fbeacb99d9d4dc
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (11)
nushell/gen-aliases.nu
Modified20 -aka tree tre
'-all' '--linecount' '--symbolic' 20 +aka tree tre
'--all' '--symbolic' 21 21 aka view wezterm imgcat
22 22 aka list ls
'--long' '--all' '--du' nushell/modules/package/db.nu
Deleteddeleted file mode 100644No text changes.
nushell/modules/package/extractor.nu
Modified 18 + let is_single_dir = (run-external tar
'--list' $
'--file=($archive)' | lines | path split | first | uniq | length) ==
1 19 + let strip =
if $is_single_dir {
1 }
else {
0 }
20 + run-external tar
'--extract' $
"--file=($archive)" $
"--directory=($target)" $
'--strip-components=($strip)' nushell/modules/package/folders.nu
Modified 5 5 const package_home =
$nu.home-path ++
'/Packages' 7 6 export def package-home [] {
12 11 const manifests =
$package_home ++
'/Manifests' 14 12 export def manifests [] {
17 +const cache =
$package_home ++
'/Cache' 18 +export def cache [] {
23 +const binaries =
$package_home ++
'/Binaries' 24 +export def binaries [] {
29 +const database =
$package_home ++
'/Database' 30 +export def database [] {
35 +const programs =
$package_home ++
'/Programs' 36 +export def programs [] {
41 +const provisions =
$package_home ++
'/Provisions' 42 +export def provisions [] {
nushell/modules/package/installer.nu
Addednew file mode 100644 15 + cd (folders manifests)
16 + let candidates = ls |
where name =~ $
"\(?i\)($query)" | get name
17 + if (
$candidates | is-empty) {
18 + print --stderr $
"No manifest for ($query) found!" 24 + if (
$candidates | has-one) {
25 + let candidate = (
$candidates | first)
26 + print $
"Found only match for ($query): ($candidate)." 27 + $package =
$candidate 29 + print $
"Found multiple matches for ($query). Pick one!" 30 + $package = (
$candidates | input list --fuzzy
"Which package to install? ")
33 + let manifest = open
$package | from nuon
34 + install-manifest
$manifest 37 +export def install-manifest [
39 + organisation: string
43 + 'version extractor': any
44 + 'relative binary path': path
47 + 'linux x64 url': any
48 + 'linux aarch64 url': any
49 + 'win32 x64 url': any
50 + 'fedora package name': any
51 + 'arch package name': any
52 + 'termux package name': any
53 + 'win32 package name': any
56 + mut url =
match (
$nu.os-info.family) {
58 + match (
$nu.os-info.arch) {
59 + 'x86_64' =>
$manifest.'linux x64 url' 60 + 'aarch64' =>
$manifest.'linux aarch64 url' 63 + 'windows' =>
$manifest.'win32 x64 url' 66 + if (
$url | is-empty) {
67 + error make { msg: $
"Manifest for ($manifest.name) coontains no suitable url for ($nu.os-info.name) ($nu.os-info.arch). Aborting." }
70 + $url = (
$url | str replace --regex --all
'\{\s*version\s*\}' $manifest.version)
72 + let artifact_path = [ (folders cache) (
$url | path basename) ] | path join
73 + if (not (
$artifact_path | path exists)) {
74 + http get --raw --max-time 30sec
$url | save --progress --raw
$artifact_path 77 + let destination = [(folders programs)
$manifest.organisation $manifest.name $manifest.version] | path join
79 + extractor unpack
$artifact_path $destination 81 + let bin =
$manifest.'relative binary path' 82 + if (
$bin | is-empty) {
83 + print $
"Manifest for ($manifest.organisation)/($manifest.name) contains to binary path." 86 + let source = [
$destination $bin] | path join
87 + if ( not (
$source | path exists)) {
88 + error make { msg: $
"Faulty manifest! Relative binary path [($source)] points to non-existent path in ($destination)." }
91 + match (
$source | path type) {
93 + let target = ([(folders binaries)
$bin] | path join)
94 + slink
$source $target 98 + |
where type ==
'file' 100 + | filter { is-executable }
103 + let target = ([(folders binaries) (
$file | path basename)] | path join)
104 + slink (
$file | path expand)
$target 108 + error make { msg: $
"Weird, ($source) is neither file nor directory..." }
nushell/modules/package/lib.nu
Modified 5 +export def has-one []: list<any> -> bool {
6 + let size =
$in | length
11 +export def get-or-
else [
18 + select -i
$column | update
$column {
if (
$in | is-empty ) {
$value }
else {
$in } } | get
$column 22 +export def is-executable []: path -> bool {
23 + match $nu.os-info.family {
25 + $env | upsert __file_for_executbale_check (
$in | path expand )
26 + run-external sh
'-c' '[ -x "$__file_for_executbale_check" ] && echo true || echo false' | into bool
30 + $in | find --regex
'(\.exe)|(\.bat)|(\.ps1)$' | is-not-empty
40 + match $nu.os-info.family {
42 + run-external ln
'--symbolic' $source $target 46 + run-external cmd
'/c' mklink
$target $source nushell/modules/package/mod.nu
Modified11 11 export module ./manifestor.nu
12 +export module ./installer.nu
nushell/modules/package/path.nu
Addednew file mode 100644 6 +export def --env set-system-path [] {
7 + let bin = (folders binaries)
8 + match $nu.os-info.family {
10 + if (
$env.PATH | find
$bin | is-empty) {
11 + let envd = [
$nu.home-dir .config environment.d] | path join
12 + if(not (
$envd | path exists)) {
13 + error make {msg: $
"systemd environment.d must exist under ($envd)!"}
15 + let packgage_path = $
'PATH = "$PATH:($bin)"' 16 + $packgage_path | save --raw ([
$envd package.conf] | path join)
17 + $env | upsert PATH
$bin 21 + if (
$env.Path | find
$bin | is-empty ) {
23 + $newPath = [Environment]::GetEnvironmentVariable\(\"Path\", \"User\"\) + \";(
$bin)\"
24 + [Environment]::SetEnvironmentVariable\(\
"Path\", $newPath, \"User\"\)" 25 + run-external powershell
'-EncodedCommand' (
$ps_command | endode base64)
26 + $env | upsert Path
$bin nushell/modules/package/provider.nu
Addednew file mode 100644 15 +export def provision [] {
nushell/modules/package/slinker.nu
Deleteddeleted file mode 100644No text changes.
tools/packages.nu
Modified