mise icon indicating copy to clipboard operation
mise copied to clipboard

Nushell config breaks repeated tab completion of executables on PATH

Open jjmark15 opened this issue 2 years ago • 2 comments

Describe the bug A clear and concise description of what the bug is.

The generated nu config for rtx breaks second time tab completion of custom executables on the PATH.

To Reproduce Steps to reproduce the behavior.

  • include rtx config in nu config
  • create new shell instance
  • tab complete an entry on the path and Ctrl + c
  • tab complete the same entry on the path
  • will result in NO RECORDS FOUND

Removal of rtx from nu config fixes the issue.

Expected behavior A clear and concise description of what you expected to happen.

PATH entry should remain found.

rtx doctor output

rtx version:
  1.30.4 linux-x64 (7bcbe6d 2023-05-23)

build:
  Target: x86_64-unknown-linux-gnu
  Features: SELF_UPDATE
  Built: Tue, 23 May 2023 00:51:54 +0000
  Rust Version: rustc 1.69.0 (84c898d65 2023-04-16)
  Profile: release

shell:
  nu
  0.80.0

rtx environment variables:
  RTX_SHELL=nu

settings:
  {"experimental": "false", "missing_runtime_behavior": "warn", "always_keep_download": "false", "always_keep_install": "false", "legacy_version_file": "true", "plugin_autoupdate_last_check_duration": "10080", "trusted_config_paths": "[]", "verbose": "false", "asdf_compat": "false", "jobs": "4", "disable_default_shorthands": "false", "log_level": "INFO", "raw": "false"}

config files:
  /home/jjones/.tool-versions

plugins:
  golang   https://github.com/kennyp/asdf-golang.git#f006a12
  gradle   https://github.com/rfrancis/asdf-gradle.git#e47df00
  java     https://github.com/halcyon/asdf-java.git#1cbc9b4
  kotlin   https://github.com/asdf-community/asdf-kotlin.git#c2536cf
  node     (core)

toolset:
  [email protected]+10, [email protected], [email protected], [email protected]

No problems found

Additional context Add any other context about the problem here.

Commenting out the line:

let-env $var.name = $"($var.value)"

in the activation script stops the prompt from breaking.

jjmark15 avatar May 30 '23 22:05 jjmark15

the issue seems to stem from the hook-env command from rtx producing a broken line.

For me, when I start a new terminal, rtx hook-env -s nu produces the following:

PATHKOTLIN_HOMEGOROOTJAVA_HOMEGOPATHPATH__RTX_DIFF__RTX_WATCHset,PATH,<MY PATH REDACTED>

This is then parsed by the nushell script but the "operation" column is clearly corrupt as it contains the name of several environment variables concatenated with the intended set operation. Therefore, when looped through later in the script, this line is skipped as the script does not recognise the operation name.

I was able to verify that this is the cause of my terminal completion issue by modifying the nushell script to manage to parse the corrupted line:

def "parse vars" [] {
  $in | lines | parse "(?P<op>set|hide),(?P<name>.+),(?P<value>.+)"
}

Obviously this does not address the underlying issue where the hook-env command produces incorrect output.

jjmark15 avatar Jun 03 '23 11:06 jjmark15

I also encountered this problem and here's the fix:

 def-env "update-env" [] {
   for $var in $in {
     if $var.op == "set" {
-      let-env $var.name = $"($var.value)"
+      if $var.name == "PATH" {
+        let-env $var.name = ($var.value | split row :)
+      } else {
+        let-env $var.name = $"($var.value)"
+      }
     } else if $var.op == "hide" {
       hide-env $var.name
     }
   }
 }

PATH is a list of strings in nushell, and so it should be treated.

ineu avatar Jul 12 '23 20:07 ineu

I couldn't repro. Is this still an issue?

texastoland avatar Mar 10 '24 03:03 texastoland

The TAB behavior works for me with the default config generated by mise activate nu, so this exact issue seems to be fixed.

There's another problem in the generated config though: it overwrites config.hooks, resetting anything that could have been there. So generally the Nushell integration is yet to be fixed: image

ineu avatar Mar 16 '24 14:03 ineu

That's why I checked this issue! Fix pending in #1763. The underlying issue is being addressed in nushell/nu_scripts#787. But IFL it'll be at least a couple months before that's available a Nushell release.

texastoland avatar Mar 16 '24 14:03 texastoland

Oh, that's great news! Thank you for the PR.

ineu avatar Mar 16 '24 16:03 ineu