repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

package.nu: force link when reinstalling

3d2e86feed8be40c8b8cb6180e8f2c7cc70231a5

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (7)

nushell/akku.nu

Deleted
deleted file mode 100644
1 -# Print information about the battery on this device
2 -def main [] {
3 - let device_directory = '/sys/class/power_supply/BAT0'
4 - if ( not ($device_directory | path exists) ) {
5 - print --stderr $"Could not find ($device_directory). Does this device have a battery? Maybe under another path?"
6 - return
7 - }
8 - let energy_full = (open ([$device_directory energy_full] | path join) | into int)
9 - let energy_now = (open ([$device_directory energy_now] | path join) | into int)
10 - let current_energy = $energy_now / $energy_full
11 - let current_energy_percent = $current_energy * 100 | into int
12 - let icon = battery_icon $current_energy_percent
13 - print $"($icon) ($current_energy_percent)%"
14 -}
16 -def battery_icon [
17 - percent: int
18 -] {
19 - let index = ( ($percent | math ceil) / 10 | math floor | into int)
20 - let icons = [
21 - '󰁺 '
22 - '󰁻 '
23 - '󰁼 '
24 - '󰁽 '
25 - '󰁾 '
26 - '󰁿 '
27 - '󰂀 '
28 - '󰂁'
29 - '󰂂 '
30 - '󰁹 '
31 - ]
32 - return ($icons | get $index)
33 -}

nushell/login.nu

Modified
8 8 use notes.nu
9 9 use yazi.nu *
10 10 use direnv.nu
11 +use akku.nu
12 13 use package

nushell/modules/akku.nu

Added
new file mode 100644
1 +# Print information about the battery on this device
2 +export def main [] {
3 + let device_directory = '/sys/class/power_supply/BAT0'
4 + if ( not ($device_directory | path exists) ) {
5 + print --stderr $"Could not find ($device_directory). Does this device have a battery? Maybe under another path?"
6 + return
7 + }
8 + let energy_full = (open ([$device_directory energy_full] | path join) | into int)
9 + let energy_now = (open ([$device_directory energy_now] | path join) | into int)
10 + let current_energy = $energy_now / $energy_full
11 + let current_energy_percent = $current_energy * 100 | into int
12 + let icon = battery_icon $current_energy_percent
13 + print $"($icon) ($current_energy_percent)%"
16 +def battery_icon [
17 + percent: int
18 +] {
19 + let index = ( ($percent | math ceil) / 10 | math floor | into int)
20 + let icons = [
21 + '󰁺 '
22 + '󰁻 '
23 + '󰁼 '
24 + '󰁽 '
25 + '󰁾 '
26 + '󰁿 '
27 + '󰂀 '
28 + '󰂁'
29 + '󰂂 '
30 + '󰁹 '
31 + ]
32 + return ($icons | get $index)

nushell/modules/package/environment_path.nu

Added
new file mode 100644
1 +# setup PATH envrionment for installed packages
3 +use ./folders.nu
5 +# sets PATH, so that it points to installed packages
6 +export def --env set-system-path [] {
7 + let bin = (folders binaries)
8 + match $nu.os-info.family {
9 + 'unix' => {
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)!"}
14 + }
15 + let packgage_path = $'PATH = "$PATH:($bin)"'
16 + $packgage_path | save --raw ([$envd package.conf] | path join)
17 + $env | upsert PATH $bin
18 + }
19 + }
20 + 'windows' => {
21 + if ( $env.Path | find $bin | is-empty ) {
22 + let ps_command = $"
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
27 + }
28 + }
29 + }

nushell/modules/package/installer.nu

Modified
55 55 let destination = [(folders programs) $manifest.organisation $manifest.name $manifest.version] | path join
56 + let bin = $manifest.'relative binary path'
57 + let source = [$destination $bin] | path join
56 59 if ($destination | path exists) {
60 + # Relink, in case activate different version
61 + force_slink $source $bin
57 62 print $'($manifest.name)/($manifest.organisation) already installed. Doing nothing.'
58 63 return
77 82 if (not ($artifact_path | path exists)) {
78 83 http get --raw --max-time 30sec $url | save --progress --raw $artifact_path
81 86 mkdir $destination
82 87 extractor unpack $artifact_path $destination
84 - let bin = $manifest.'relative binary path'
85 89 if ($bin | is-empty) {
86 90 print $"Manifest for ($manifest.organisation)/($manifest.name) contains to binary path."
87 91 return
89 - let source = [$destination $bin] | path join
90 93 if ( not ($source | path exists)) {
91 94 error make { msg: $"Faulty manifest! Relative binary path [($source)] points to non-existent path in ($destination)." }
96 + force_slink $source $bin
99 +def force_slink [
100 + source: path
101 + target: path
102 +] {
94 103 match ($source | path type) {
95 104 'file' => {
96 - let target = ([(folders binaries) ($bin | path basename)] | path join)
105 + let target = ([(folders binaries) ($target | path basename)] | path join)
97 106 print $'Linking ($source) to ($target)'
107 + if ($target | path exists) {
108 + rm $target
98 110 slink $source $target
100 112 'directory' => {
105 117 | par-each {
106 118 |file|
107 119 let target = ([(folders binaries) ($file | path basename)] | path join)
120 + print $'Linking ($source) to ($target)'
121 + if ($target | path exists) {
122 + rm $target
108 124 slink ($file | path expand) $target

nushell/modules/package/path.nu

Deleted
deleted file mode 100644
1 -# setup PATH envrionment for installed packages
3 -use ./folders.nu
5 -# sets PATH, so that it points to installed packages
6 -export def --env set-system-path [] {
7 - let bin = (folders binaries)
8 - match $nu.os-info.family {
9 - 'unix' => {
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)!"}
14 - }
15 - let packgage_path = $'PATH = "$PATH:($bin)"'
16 - $packgage_path | save --raw ([$envd package.conf] | path join)
17 - $env | upsert PATH $bin
18 - }
19 - }
20 - 'windows' => {
21 - if ( $env.Path | find $bin | is-empty ) {
22 - let ps_command = $"
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
27 - }
28 - }
29 - }
30 -}

nushell/modules/package/provider.nu

Modified
8 8 # It depends on the availablity of packages in their given source.
10 10 use ./folders.nu
11 -use ./path.nu
11 +use ./environment_path.nu
12 12 use ./installer.nu
14 14 export def provision [] {
44 - # check if installed packages are synced with current manifests
45 43 # check if current installed packages are installed via correct source
47 44 # uninstall non-provisioned
48 - # setup path
46 + environment_path setup