| 1 | ## our_shell: ysh
|
| 2 |
|
| 3 | #### default prompt doesn't confuse OSH and YSH
|
| 4 |
|
| 5 | # Special ysh prefix if PS1 is set
|
| 6 |
|
| 7 | # TODO: use PS1= temp binding
|
| 8 | setglobal ENV.PS1 = r'\$ '
|
| 9 | $[ENV.SH] -i -c 'echo "/$[get(ENV, "PS1")]/ /$[get(__defaults__, "PS1")]/"'
|
| 10 | call propView(ENV)->erase('PS1')
|
| 11 |
|
| 12 | # No prefix if it's not set, since we already have \s for YSH
|
| 13 | $[ENV.SH] -i -c 'echo "/$[get(ENV, "PS1")]/ /$[get(__defaults__, "PS1")]/"'
|
| 14 |
|
| 15 | ## STDOUT:
|
| 16 | /ysh \$ / /null/
|
| 17 | /null/ /\s-\v\$ /
|
| 18 | ## END
|
| 19 |
|
| 20 | #### promptVal() with various values
|
| 21 |
|
| 22 | shopt -s ysh:upgrade
|
| 23 |
|
| 24 | var x = io.promptVal('$')
|
| 25 |
|
| 26 | # We're not root, so it should be $
|
| 27 | echo x=$x
|
| 28 |
|
| 29 | var x = io.promptVal('w')
|
| 30 |
|
| 31 | assert [x === $(pwd)]
|
| 32 | echo pass
|
| 33 |
|
| 34 | ## STDOUT:
|
| 35 | x=$
|
| 36 | pass
|
| 37 | ## END
|
| 38 |
|
| 39 | #### promptVal() with invalid chars
|
| 40 |
|
| 41 | # \D{} will be supported with date and time functions
|
| 42 | var x = io.promptVal('D')
|
| 43 | echo x=$x
|
| 44 |
|
| 45 | # something else
|
| 46 | var x = io.promptVal('/')
|
| 47 | echo x=$x
|
| 48 |
|
| 49 | var x = io.promptVal('ZZ')
|
| 50 | echo x=$x
|
| 51 |
|
| 52 | ## status: 3
|
| 53 | ## STDOUT:
|
| 54 | x=<Error: \D{} not in promptVal()>
|
| 55 | x=<Error: \/ is invalid or unimplemented in $PS1>
|
| 56 | ## END
|
| 57 |
|
| 58 |
|
| 59 | #### ysh respects PS1
|
| 60 |
|
| 61 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 62 | echo 'echo hi' | $[ENV.SH] -i
|
| 63 |
|
| 64 | ## STDOUT:
|
| 65 | hi
|
| 66 | ^D
|
| 67 | ## END
|
| 68 | ## stderr-json: "ysh myprompt$ ysh myprompt$ "
|
| 69 |
|
| 70 | #### ysh respects renderPrompt() over PS1
|
| 71 |
|
| 72 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 73 |
|
| 74 | cat >yshrc <<'EOF'
|
| 75 | func renderPrompt(io) {
|
| 76 | var parts = []
|
| 77 | call parts->append('hi')
|
| 78 | call parts->append(io.promptVal('$'))
|
| 79 | call parts->append(' ')
|
| 80 | return (join(parts))
|
| 81 | }
|
| 82 | EOF
|
| 83 |
|
| 84 | echo 'echo hi' | $[ENV.SH] -i --rcfile yshrc
|
| 85 |
|
| 86 | ## STDOUT:
|
| 87 | hi
|
| 88 | ^D
|
| 89 | ## END
|
| 90 | ## stderr-json: "hi$ hi$ "
|
| 91 |
|
| 92 | #### renderPrompt() doesn't return string
|
| 93 |
|
| 94 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 95 |
|
| 96 | cat >yshrc <<'EOF'
|
| 97 | func renderPrompt(io) {
|
| 98 | return ([42, 43])
|
| 99 | }
|
| 100 | EOF
|
| 101 |
|
| 102 | echo 'echo hi' | $[ENV.SH] -i --rcfile yshrc
|
| 103 |
|
| 104 | ## STDOUT:
|
| 105 | hi
|
| 106 | ^D
|
| 107 | ## END
|
| 108 | ## stderr-json: "<Error: renderPrompt() should return Str, got List> <Error: renderPrompt() should return Str, got List> "
|
| 109 |
|
| 110 |
|
| 111 | #### renderPrompt() raises error
|
| 112 |
|
| 113 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 114 |
|
| 115 | cat >yshrc <<'EOF'
|
| 116 | func renderPrompt(io) {
|
| 117 | error 'oops'
|
| 118 | }
|
| 119 | EOF
|
| 120 |
|
| 121 | echo 'echo hi' | $[ENV.SH] -i --rcfile yshrc
|
| 122 |
|
| 123 | ## STDOUT:
|
| 124 | hi
|
| 125 | ^D
|
| 126 | ## END
|
| 127 | ## stderr-json: "<Runtime error: oops><Runtime error: oops>"
|
| 128 |
|
| 129 |
|
| 130 | #### renderPrompt() has wrong signature
|
| 131 |
|
| 132 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 133 |
|
| 134 | cat >yshrc <<'EOF'
|
| 135 | func renderPrompt() {
|
| 136 | error 'oops'
|
| 137 | }
|
| 138 | EOF
|
| 139 |
|
| 140 | echo 'echo hi' | $[ENV.SH] -i --rcfile yshrc
|
| 141 |
|
| 142 | ## STDOUT:
|
| 143 | hi
|
| 144 | ^D
|
| 145 | ## END
|
| 146 | ## stderr-json: "<Runtime error: Func 'renderPrompt' takes no positional args, but got 1><Runtime error: Func 'renderPrompt' takes no positional args, but got 1>"
|
| 147 |
|