mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 22:57:46 +00:00
add update-path.nu (#303)
This commit is contained in:
parent
adb76b3e9c
commit
dab62c255b
1 changed files with 37 additions and 0 deletions
37
helpers/update-path.nu
Normal file
37
helpers/update-path.nu
Normal file
|
@ -0,0 +1,37 @@
|
|||
# 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 '%' && $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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue