nu_scripts/sourced/update-path.nu
Auca Coyan bc6273d971
🐛 fix a couple of parser errors (#782)
This is some legwork to the CI
- [x] fix one `get-row.nu` before 0.60, just because it was easy
- [x] `modules/formats/to-ini.nu`
- [x] `modules/git/git-v2.nu`
- [x] `modules/git/git.nu`
- [x] `modules/log/log.nu`
- [x] `modules/weather/weatherdark.nu`
- [x] `sourced/api_wrappers/worlframalpha.nu`
- [x] `sourced/cool-oneliners/pwd-short.nu`
- [x] `sourced/github/branch-protections/branch-protections.nu`
- [x] `sourced/gitlab/gitlab.nu`
- [x] `sourced/misc/nu_defs.nu`
- [x] `sourced/update-path.nu`
- [x] `sourced/webscraping/shell_starts.nu`
I moved some auto-generated commands:
- [x] `ack` 
- [x] `as`
- [x] `curl`
- [x] `fsarprc`
- [x] `fsarpri`
- [x] `godoc`
- [x] `mysql` 
- [x] and `xgettext` 
to custom, so we keep the modifications.
I had to comment some of the flags because the parser is not able to
parse some flags. Those are explained in comments
2024-03-10 14:05:01 -05:00

38 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 [] {
$env.Path = ($env.Path|append (get-paths-from-registry)|uniq)
}
}