nu_scripts/sourced/update-path.nu
Mel Massadian c47ccd42b8
refactor: (#418)
* refactor:  move in one commit

Eveything in modules should probably be changed to `exported` defs.
The idea is to move everything first to keep proper history.

* refactor: 📝 add modules readme (wip)

* refactor:  small move

* refactor: 📝 changed nestring, updated modules readme

* refactor: 📝 to document or not to document

* fix: 🐛 themes

replaced the template to use `main` and regenerated them
from lemnos themes.

* Revert "fix: 🐛 themes"

This reverts commit 4918d3633c.

* refactor:  introduce sourced

- Created a source `root` in which sourcable demos are stored.
  Some might get converted to modules later on.
- Moved some files to bin too.

* fix: 🐛 fehbg.nu

* fix: 🐛 modules/after.nu

* moved some other stuff around

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-04-25 17:56:25 -05:00

37 lines
1.3 KiB
Plaintext

# The purpose of this module is to automatically update Path variable on Windows since Windows is unable to do it on its own forcing users to restart terminal to pick up updates
# Usage: import this into your config.nu and then add the update-path function to your pre_prompt hook
module update-path {
def parse-paths [] {
where name == Path
| get value.0
| str trim -c (char double_quote)
| split row (char esep)
| par-each {|path|
let suffix = if $path ends-with (char path_sep) {(char path_sep)} else {''} # necessary because nushell strips trailing path separators which breaks uniq later on
$path
| path split
| each {|elem|
if $elem starts-with '%' and $elem ends-with '%' {
$env
| get ($elem|str trim -c '%')
} else {
$elem
}
}
| path join
| append $suffix
| str join
}
}
def get-paths-from-registry [] {
registry query --hkcu environment
| parse-paths
| append (registry query --hklm 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'| parse-paths)
}
export def-env update-path [] {
let-env Path = ($env.Path|append (get-paths-from-registry)|uniq)
}
}