fix(nu): support windows nicely
The main thing we are doing is setting the `HOME` and `USER` env variables so we can use comon variables over linux and windows. There is also a windows wezterm issue `shell_integration.osc133` feature needs to be disabled. This will stop the prompt adding a new line on every char typed into the prompt.
This commit is contained in:
parent
18ce1c8695
commit
42cbeed7de
3 changed files with 22 additions and 88 deletions
|
|
@ -1,3 +1,8 @@
|
|||
if ((sys host | get name) == "Windows") {
|
||||
$env.HOME = $env.USERPROFILE
|
||||
$env.USER = $env.USERNAME
|
||||
}
|
||||
|
||||
use path.nu *
|
||||
|
||||
use fzf.nu *
|
||||
|
|
@ -5,9 +10,6 @@ use neovim.nu *
|
|||
use prompt.nu *
|
||||
use sapling.nu *
|
||||
use nvm.nu *
|
||||
use rvm.nu *
|
||||
|
||||
nvm use default
|
||||
|
||||
$env.config = {
|
||||
show_banner: false,
|
||||
|
|
@ -15,10 +17,11 @@ $env.config = {
|
|||
env_change: {
|
||||
PWD: [
|
||||
{|_, after| nvm dir-hook $after }
|
||||
{|_, after| rvm-dir-hook $after }
|
||||
{|_, after| node-modules-dir-hook $after }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$env.config.show_banner = false
|
||||
$env.config.shell_integration.osc133 = false
|
||||
|
|
|
|||
|
|
@ -1,84 +1,13 @@
|
|||
|
||||
def 'nvm path' [subdir?: string]: nothing -> string {
|
||||
if ($subdir | into string | str length) == 0 {
|
||||
return $"($env.HOME)/.nvm"
|
||||
}
|
||||
|
||||
$"($env.HOME)/.nvm/($subdir)"
|
||||
}
|
||||
|
||||
export def 'nvm get-alias' [alias: string]: nothing -> string {
|
||||
mut alias_version = if ($alias | find "stable" | is-not-empty) {
|
||||
["lts/*"]
|
||||
} else {
|
||||
nvm aliases | where {|x| $x == $alias}
|
||||
}
|
||||
|
||||
if $alias_version == ["stable"] {
|
||||
$alias_version = ["lts/*"]
|
||||
}
|
||||
|
||||
if ($alias_version | is-empty) {
|
||||
return null
|
||||
}
|
||||
|
||||
if ($alias_version | length) > 1 {
|
||||
$alias_version = [$"($alias_version | first)/*"]
|
||||
}
|
||||
|
||||
let version = (open ([(nvm path "alias"), ($alias_version | first)] | path join)) | str trim
|
||||
if not ($version | str starts-with "v") {
|
||||
return (nvm get-alias $version)
|
||||
}
|
||||
|
||||
$version
|
||||
}
|
||||
|
||||
def 'nvm index' [] {
|
||||
http get 'https://nodejs.org/dist/index.json' | get version
|
||||
}
|
||||
|
||||
export def 'nvm aliases' [] {
|
||||
ls -a ...(glob (nvm path "alias/**/*"))
|
||||
| each {|p| $p.name | path relative-to (nvm path "alias") }
|
||||
| filter {|p| not ($p | str ends-with "*")}
|
||||
| uniq
|
||||
}
|
||||
|
||||
export def 'nvm list' [] {
|
||||
ls -a (nvm path "versions/node")
|
||||
| each {|p| $p.name | path relative-to (nvm path "versions/node") }
|
||||
| filter {|p| not ($p | str ends-with "*")}
|
||||
}
|
||||
|
||||
export def 'nvm resolve' [version: string] {
|
||||
let resolved_version = (nvm list | find $version)
|
||||
let resolved_alias = (nvm get-alias $version)
|
||||
if (($resolved_version | length) != 1) and ($resolved_alias | is-empty) {
|
||||
(error make --unspanned { msg: $"Unable to resolve '($version)'" })
|
||||
}
|
||||
|
||||
if not ($resolved_version | is-empty) {
|
||||
$resolved_version | first
|
||||
} else {
|
||||
$resolved_alias
|
||||
}
|
||||
}
|
||||
|
||||
export def --env 'nvm use' [version: string] {
|
||||
let resolved = (nvm resolve $version)
|
||||
let node_path = [(nvm path "versions/node") $resolved] | path join
|
||||
|
||||
$env.PATH = $env.PATH
|
||||
| split row ":"
|
||||
| where {|x| not ($x | str starts-with (nvm path "versions/node"))}
|
||||
| prepend ([$node_path "bin"] | path join)
|
||||
| str join ":"
|
||||
}
|
||||
|
||||
export def --env 'nvm dir-hook' [dir: string] {
|
||||
let file = $"($dir)/.nvmrc"
|
||||
if ($file | path exists) and ($file | path type) == "file" {
|
||||
nvm use (open $file | lines | get 0) | str trim
|
||||
let version = (open $file | lines | get 0 | str trim)
|
||||
if (nvm list | find $version | is-empty) {
|
||||
nvm install $version
|
||||
nvm use $version
|
||||
npm i -g typescript-language-server typescript emmet-ls cspell vscode-langservers-extracted yarn
|
||||
} else {
|
||||
nvm use $version | complete | ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
|
||||
|
||||
|
||||
export-env {
|
||||
$env.GOPATH = $"($env.HOME)/Code"
|
||||
$env.GOPATH = if ($env.COMPUTERNAME == "LAFITE") {
|
||||
$"D:/Code"
|
||||
} else {
|
||||
$"($env.HOME)/Code"
|
||||
}
|
||||
$env.PATH = $env.PATH
|
||||
| split row ":"
|
||||
| prepend ([$env.HOME ".cargo" "bin"] | path join)
|
||||
| str join ":"
|
||||
}
|
||||
|
||||
export def --env node-modules-dir-hook [dir: string] {
|
||||
let nodePath = ([$dir, "node_modules", ".bin"] | path join)
|
||||
if ($nodePath | path exists) {
|
||||
$env.PATH = $env.PATH
|
||||
| split row ":"
|
||||
| where {|x| not ($x | str contains "node_modules")}
|
||||
| prepend $nodePath
|
||||
| str join ":"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue