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

Confusing errors with PS1 is inherited (from bash etc.) #989

Closed
NoahTheDuke opened this issue Sep 27, 2021 · 10 comments
Closed

Confusing errors with PS1 is inherited (from bash etc.) #989

NoahTheDuke opened this issue Sep 27, 2021 · 10 comments

Comments

@NoahTheDuke
Copy link

I installed oil using homebrew, which says is on 0.9.2. When I run oil in bash, even tho I have a completely blank ~/.config/oil/oshrc, I see errors related to my bash set up:

noah@Noahs-MBP ~
$ oil
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
                                  ^
(source.PromptCommand spid:-1):2: Invalid char escape in double quoted string
oil$

According to the docs, neither .bash_profile nor .bashrc should be loaded. If I comment out or rename them, then oil opens normally when run from a fresh process. Now that I've written this out, does oil inherit this stuff? If I comment out/rename those files, but don't reload my current bash process, oil throws the above error.

I don't know exactly what's happening, so any help would be great.

@andychu
Copy link
Contributor

andychu commented Sep 27, 2021

oil will run ~/.config/oil/oilrc and osh will run ~/.config/oil/oshrc -- maybe that's the problem?

Generally speaking osh is better to try interactively right now.

oil works interactively but it's probably more useful as a REPL like python (i.e. it gives more strict errors)

@NoahTheDuke
Copy link
Author

Oops, I should have run osh. However, that gives me the following:

noah@Noahs-MBP ~
$ osh
  __bp_precmd_invoke_cmd
  ^~~~~~~~~~~~~~~~~~~~~~
(source.PromptCommand spid:-1):1: '__bp_precmd_invoke_cmd' not found
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
  ^~~~~~~~~~~~
(source.PromptCommand spid:-1):2: '_direnv_hook' not found
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
               ^~~~~~~~~~~~~~
(source.PromptCommand spid:-1):2: '__posh_git_ps1' not found
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~
(source.PromptCommand spid:-1):2: '__iterm2_prompt_command' not found
  __bp_interactive_mode
  ^~~~~~~~~~~~~~~~~~~~~
(source.PromptCommand spid:-1):3: '__bp_interactive_mode' not found
<Error: unbalanced \[ and \]>

If I restart my terminal session (which then doesn't load .bash_profile or .bashrc), this goes away.

@andychu
Copy link
Contributor

andychu commented Sep 27, 2021

Ah can you do echo $PS1 and paste the output here? Before you start osh and after if possible

I think the problem might be that osh is inherting a $PS1 from bash or zsh. And then those functions aren't defined.

The error message needs to be better, the (source.PromptCommand stuff should be replaced with something pointing to the real location

@NoahTheDuke
Copy link
Author

Here you go!

noah@Noahs-MBP ~
$ echo $PS1
\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w \[\e[1;34m\]\n$\[\e[0m\]
noah@Noahs-MBP ~
$ osh
  __bp_precmd_invoke_cmd
  ^~~~~~~~~~~~~~~~~~~~~~
(source.PromptCommand spid:-1):1: '__bp_precmd_invoke_cmd' not found
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
  ^~~~~~~~~~~~
(source.PromptCommand spid:-1):2: '_direnv_hook' not found
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
               ^~~~~~~~~~~~~~
(source.PromptCommand spid:-1):2: '__posh_git_ps1' not found
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~
(source.PromptCommand spid:-1):2: '__iterm2_prompt_command' not found
  __bp_interactive_mode
  ^~~~~~~~~~~~~~~~~~~~~
(source.PromptCommand spid:-1):3: '__bp_interactive_mode' not found
<Error: unbalanced \[ and \]> echo $PS1
\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w \[\e[1;34m\]\n$\[\e[0m\]
  __bp_precmd_invoke_cmd
  ^~~~~~~~~~~~~~~~~~~~~~
(source.PromptCommand spid:-1):1: '__bp_precmd_invoke_cmd' not found
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
  ^~~~~~~~~~~~
(source.PromptCommand spid:-1):2: '_direnv_hook' not found
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
               ^~~~~~~~~~~~~~
(source.PromptCommand spid:-1):2: '__posh_git_ps1' not found
  _direnv_hook;__posh_git_ps1 "\\[\[\e[0;32m\]\u@\h \[\e[0;33m\]\w " " \[\e[1;34m\]\n\$\[\e[0m\] ";__iterm2_prompt_command
                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~
(source.PromptCommand spid:-1):2: '__iterm2_prompt_command' not found
  __bp_interactive_mode
  ^~~~~~~~~~~~~~~~~~~~~
(source.PromptCommand spid:-1):3: '__bp_interactive_mode' not found
<Error: unbalanced \[ and \]>

and with a blank .bash_profile & .bashrc:

Noahs-MBP:~ noah$ echo $PS1
\h:\W \u\$
Noahs-MBP:~ noah$ osh
osh$ echo $PS1

osh$

@andychu
Copy link
Contributor

andychu commented Sep 27, 2021

OK yeah the issue is that it is being inherited.

If you do

PS1=''  # reset it first
osh

then you can avoid having to change .bash_profile or .bashrc.

I can see how this is confusing. The way it works is that environment variables like PS1 are inherited.

But bin/osh has to inherit to be POSIX compatible, and it has to use the var PS1

Maybe we can make bin/oil not inherit, but that's a separate issue #498

I think it will help if the errors are better, or maybe a section of the manual should say to reset PS1

@andychu andychu changed the title Issues with auto-loading/inheriting bash settings Confusing errors with PS1 is inherited (from bash etc.) Sep 27, 2021
@andychu
Copy link
Contributor

andychu commented Sep 27, 2021

Thanks for trying it and sending feedback! I'll think about what to do here, but for now I think PS1='' should let you get past this error. Let me know what else happens; I would like to put more things on this page:

https://github.com/oilshell/oil/wiki/Shell-Programs-That-Run-Under-OSH

@NoahTheDuke
Copy link
Author

excellent, thank you for the help!

@andychu andychu mentioned this issue Oct 3, 2021
2 tasks
@andychu
Copy link
Contributor

andychu commented Oct 3, 2021

(notes)

2 issues with source locations that would make some of the errors better

  • PROMPT_COMMAND doesn't have span ID
  • PS1 is apparently not attributed to anything, needs an alloc.ctx_Location
    • PromptEvaluator has to be careful because it is used for ${x@P} as well

andychu pushed a commit that referenced this issue Oct 3, 2021
Move the unicode section.

Mentioned the PS1 issue in #989.

Also related to #993.
@andychu
Copy link
Contributor

andychu commented Oct 4, 2021

Improving the error messages:

7c577c8

Part of #993

@andychu
Copy link
Contributor

andychu commented Nov 10, 2021

Released last month https://www.oilshell.org/release/0.9.3/

@andychu andychu closed this as completed Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants