nushell: Starship process fails to spawn until a command has been run

Describe the bug When attempting to use a Starship prompt, the command to display the prompt in the terminal fails with the error “failed to spawn process” until a command has been run.

To Reproduce Steps to reproduce the behavior:

  1. (not sure if this is related) Install nushell 0.20.0 using cargo install
  2. Install nushell 0.25.0 and starship 0.45.1 using cargo install
  3. Run config set prompt "echo $(starship prompt)"
  4. Start a new instance of nushell. There should be an error:
error: Failed to spawn process
  ┌─ shell:1:8
  │
1 │ echo $(starship prompt)
  │        ^^^^^^^^ failed to spawn
  1. Pressing enter without entering a command will cause the error message to be printed again, as nushell attempts to display the prompt once more.

Additionally:

  1. Run any command. This should cause the next prompt to display normally without error.
  2. Hereafter, when pressing enter or running any subsequent commands, the prompt should display normally without error.

Expected behavior The prompt should be printed normally without error when nushell starts and each time the enter key is pressed.

Screenshots

Nushell fails to show the prompt correctly until a command has been run:

image

Configuration (please complete the following information):

Output of version | pivot:

  #         Column0                            Column1                      
────────────────────────────────────────────────────────────────────────────
   0   version              0.25.0                                          
   1   branch               main                                            
   2   short_commit         7e4e7fa4                                        
   3   commit_hash          7e4e7fa4a610730850f050b33803a539eb3c1d57        
   4   commit_date          2021-01-05 17:32:08                             
   5   build_os             windows-x86_64                                  
   6   rust_version         rustc 1.50.0-nightly (1c389ffef 2020-11-24)     
   7   rust_channel         nightly-x86_64-pc-windows-msvc (default)        
   8   cargo_version        cargo 1.50.0-nightly (bfca1cd22 2020-11-24)     
   9   pkg_version          0.25.0                                          
  10   build_time           2021-01-05 18:13:29                             
  11   build_rust_channel   release                                         
  12   features             ctrlc, default, directories, dirs, git,         
                            ichwh, ptree, rich-benchmark, rustyline, term,  
                            uuid, which, zip                                

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 17
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Nice to have it working properly. I changed it into a custom command so I have this in my startup = [ ] section of the config.toml "def starship_prompt_tweak [] {with-env [PWD $(pwd)] { starship.exe prompt | str collect }}", and then on prompt I have prompt = "starship_prompt_tweak"

Hi, not sure if somebody mentioned it, but I’ve managed to bypass first issue will be one 'command' behind with following hack:

config set prompt 'with-env [PWD $(pwd)] { echo $(starship prompt) }'

(without additional echo, I’m getting some extra newline)

P.S. I’m currently running 0 │ 0.26.1 │ main │ c83aea3c

Looks like the context isn’t fully setup until after the first command runs

This might also be causing an issue I’m seeing where the current directory in the prompt will be one ‘command’ behind, if that makes sense.

~/test
❯ ls
───┬──────┬──────┬──────┬────────────
 # │ name │ type │ size │  modified
───┼──────┼──────┼──────┼────────────
 0 │ bar  │ Dir  │  0 B │ 3 secs ago
 1 │ foo  │ Dir  │  0 B │ 7 secs ago
───┴──────┴──────┴──────┴────────────

~/test
❯ cd bar

~/test
❯ pwd
C:\Users\h355305\test\bar

~/test/bar
❯ cd ..

~/test/bar
❯ pwd
C:\Users\h355305\test

~/test
❯

seems collect itself is enough. trim eats space after “>”, so: config set prompt 'with-env [PWD $(pwd)] { starship prompt | str collect }'

I’ve found that this helps with extra newlines "def starship_prompt_trim [] {starship.exe prompt | str collect | str trim}". Maybe some combination of both will help?

i compiled the latest starship to try and diagnose what was going on and it’s just weird. sometimes starship prompt works. sometimes it doesn’t. I can’t tell whether it’s on our end or starships end.

I tried to be clever and create a custom command in my startup = [ ] section like this "def run_starship [] {c:\\cartar\\debug\\starship.exe prompt}", and then change my prompt to prompt = run_starship and I get a starship prompt sometimes and then i change directories and the directory/pwd isn’t set properly giving the impression that it’s one directory behind.

My current directory isn’t one behind on my side

image

Note that I do have to actually enter a command (or anything really) to have starship started. If I just press enter, it repeat the error message:

image