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

osh: bash prompt special characters #2235

Open
simonLeary42 opened this issue Jan 23, 2025 · 3 comments
Open

osh: bash prompt special characters #2235

simonLeary42 opened this issue Jan 23, 2025 · 3 comments

Comments

@simonLeary42
Copy link
Collaborator

This very well may be out of scope, feel free to close the issue if it is.

https://www.gnu.org/software/bash/manual/html_node/Controlling-the-Prompt.html

$ for symbol in a d e h H j l n r s t T @ A u v V w W '!' '#' '$'; do PS1="\\$symbol" osh; done

^D
<Error: \d is invalid or unimplemented in $PS1>
^D

^D
wheatley
^D
wheatley.local
^D
<Error: \j is invalid or unimplemented in $PS1>
^D
<Error: \l is invalid or unimplemented in $PS1>
^D


^D

^D
osh
^D
<Error: \t is invalid or unimplemented in $PS1>
^D
<Error: \T is invalid or unimplemented in $PS1>
^D
<Error: \@ is invalid or unimplemented in $PS1>
^D
11:11
^D
simon
^D
0.24.0
^D
<Error: \V is invalid or unimplemented in $PS1>
^D
~
^D
simon
^D
<Error: \! is invalid or unimplemented in $PS1>
^D
<Error: \# is invalid or unimplemented in $PS1>
^D
$
^D

the above example does not check \D, \nnn, \[, or \], simply out of laziness on my part.

@simonLeary42
Copy link
Collaborator Author

R(r'\\[adehHjlnrstT@AuvVwW!#$\\]', Id.PS_Subst),

_devbuild.gen.id_kind_asdl.Id is a mystery to me.

@andychu
Copy link
Contributor

andychu commented Jan 23, 2025

Thanks for trying it :)

In theory all of these things are in scope, but we are focused more on "batch" scripts (e.g. $IFS incompatibilities) and YSH at the moment

So any contributions are welcome

Or if you have a specific feature that's blocking a specific program, that's interesting

But right now I don't see contributors who are going to implement missing prompt features based on the bash manual


The Id is basically an "enum" generated by Zephyr ASDL - a domain-specific language for algebraic data types that we borrowed from CPython - https://www.oilshell.org/blog/2016/12/11.html

The Id is used to represent all the code. e.g. here Id.Lit_Chars and Id.LeftDoubleQuote are integers that represent code. It's a big tree

The $PS1 string is also represented as a piece of code, so it has Id.PS_Subst

$ bin/osh -n -c 'echo "hi $x"'
(C (w <Lit_Chars echo>) (w (DQ <Lit_Chars "hi "> ($ x))))
andy@hoover:~/git/oils-for-unix/oils$ bin/osh --ast-format text -n -c 'echo "hi $x"'
(command.Simple
  blame_tok:(Token id:Lit_Chars length:4 col:0 line:(SourceLine line_num:1 content:"echo \"hi $x\"" src:(source.CFlag)))
  more_env:[]
  words:[
    (CompoundWord parts:[...0x7f151aa29c20])
    (CompoundWord
      parts:[
        (DoubleQuoted
          left:(Token id:Left_DoubleQuote length:1 col:5 line:...0x7f151a8dc770)
          parts:[(Token id:Lit_Chars length:3 col:6 line:...0x7f151a8dc770) (SimpleVarSub tok:(Token id:VSub_DollarName length:2 col:9 line:...0x7f151a8dc770))]
          right:(Token id:Right_DoubleQuote length:1 col:11 line:...0x7f151a8dc770)
        )
      ]
    )
  ]
  is_last_cmd:F
)

@andychu
Copy link
Contributor

andychu commented Jan 23, 2025

The tests for the prompt are here:

https://oils.pub/release/0.26.0/test/spec.wwz/osh-py/prompt.html

$ test/spec.sh prompt 
prompt.test.sh
case    line    bash    osh
  0       3     pass    pass    sh -i
  1      14     pass    pass    \[\] are non-printing
  2      21     pass    pass    literal escapes
  3      26     pass    pass    special case for $

Writing failing tests is usually about half the work, and we merge failing tests ... if those exist, then other people may be motivated to make them go green (and that has happened before)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants