Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rbenv module #1007

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/rbenv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This script provides minimal working rbenv setup.
It can be used by importing its exported commands via:

```
use path/to/rbenv.nu *
use path/to/rbenv.nu
```

With `path/to` being either the relative path of the file to your current working directory or its absolute path.
45 changes: 13 additions & 32 deletions modules/rbenv/rbenv.nu
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
# rbenv
export-env {
load-env {
PATH: ($env.PATH | split row (char esep) | prepend [$"($env.HOME)/.rbenv/bin" $"($env.HOME)/.rbenv/shims"])
RBENV_VERSION: ""
RBENV_VERSION_OLD: ""
RBENV_SHELL: "nu"
}
export-env {
use std/util "path add"

$env.RBENV_SHELL = 'nu'
$env.RBENV_VERSION = ''
path add $"($env.HOME)/.rbenv/bin"
path add $"($env.HOME)/.rbenv/shims"
}

export def --env main [
command?: string@'nu-complete rbenv',
...args
] {
let new_env = if $command in ["rehash", "shell"] {
# implement each on indiviudaly e.g.
if $command == "shell" {
{ RBENV_VERSION_OLD: $env.RBENV_VERSION RBENV_VERSION: $args.0 }
} else {
error make { msg: $"`($command)` command is not supported yet" }
}
export def --env "shell" [version: string] {
let run = (^rbenv sh-shell $version | complete)
if ($run.exit_code == 0) {
$env.RBENV_VERSION_OLD = ($env.RBENV_VERSION | default "")
$env.RBENV_VERSION = $version
} else {
if ($command | is-empty) {
^rbenv
} else {
^rbenv $command $args
}
{}
print -e $run.stderr
}
load-env $new_env
}

def 'nu-complete rbenv' [] {
^rbenv help
| lines
| where ($it | str starts-with " ")
| each {|entry| $entry | split row ' ' | get 0 }
}
Loading