diff --git a/site-modules/core/files/nushell/config.nu b/site-modules/core/files/nushell/config.nu index fb4105b..82e6426 100644 --- a/site-modules/core/files/nushell/config.nu +++ b/site-modules/core/files/nushell/config.nu @@ -5,6 +5,7 @@ use neovim.nu * use prompt.nu * use sapling.nu * use nvm.nu * +use rvm.nu * nvm use default @@ -14,6 +15,7 @@ $env.config = { env_change: { PWD: [ {|_, after| nvm dir-hook $after } + {|_, after| rvm-dir-hook $after } ] } } diff --git a/site-modules/core/files/nushell/scripts/path.nu b/site-modules/core/files/nushell/scripts/path.nu index e20ae1c..142f854 100644 --- a/site-modules/core/files/nushell/scripts/path.nu +++ b/site-modules/core/files/nushell/scripts/path.nu @@ -1,4 +1,8 @@ export-env { $env.GOPATH = $"($env.HOME)/Code" + $env.PATH = $env.PATH + | split row ":" + | prepend ([$env.HOME ".cargo" "bin"] | path join) + | str join ":" } diff --git a/site-modules/core/files/nushell/scripts/rvm.nu b/site-modules/core/files/nushell/scripts/rvm.nu new file mode 100644 index 0000000..09ee686 --- /dev/null +++ b/site-modules/core/files/nushell/scripts/rvm.nu @@ -0,0 +1,41 @@ +# Plugin to manage ruby versions with rvm by reading the `.ruby-version` and +# `.ruby-gemset` files to install and setup your ruby version and the gemset. +# +# Like the custom nvmrc one this will only do something if you have the +# `.ruby-version` file in the current directory to try and reduce the amount of +# work that gets done on `cd` + +def file-exists [file: string] { + ($file | path exists) and ($file | path type) == "file" +} + +export def --env rvm-use [version: string, gemset?: string] { + let env_map = if ($gemset | is-empty) { + (bash --login -c $"rvm use ($version); env" | lines | split column "=" | group-by column1) + } else { + (bash --login -c $"rvm use ($version); rvm gemset use --create ($gemset); env" | lines | split column "=" | group-by column1) + } + + let old_env = $env.PATH | split row ":" | filter { not ($in | str contains "rvm") } + let new_env = $env_map.PATH.column2 | split row ":" | filter { $in | str contains "rvm" } + + load-env { + RUBY_VERSION: ($env_map.RUBY_VERSION.column2 | first | str trim), + GEM_HOME: ($env_map.GEM_HOME.column2 | first | str trim), + GEM_PATH: ($env_map.GEM_PATH.column2 | first | str trim), + IRBRC: ($env_map.IRBRC.column2 | first | str trim), + MY_RUBY_HOME: ($env_map.MY_RUBY_HOME.column2 | first | str trim), + rvm_path: ($env_map.rvm_path.column2 | first | str trim), + PATH: ($old_env | prepend $new_env | uniq | str join ":"), + } +} + +export def --env rvm-dir-hook [dir: string] { + let ruby_version_file = $"($dir)/.ruby-version" + let ruby_gemset_file = $"($dir)/.ruby-gemset" + if (file-exists $ruby_gemset_file) { + rvm-use (open $ruby_version_file | lines | get 0) (open $ruby_gemset_file | lines | get 0) + } else if (file-exists $ruby_version_file) { + rvm-use (open $ruby_version_file | lines | get 0) "" + } +}