| 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 $ and w
|
| 21 |
|
| 22 | var x = io.promptVal('$')
|
| 23 |
|
| 24 | # We're not root, so it should be $
|
| 25 | echo x=$x
|
| 26 |
|
| 27 | var x = io.promptVal('w')
|
| 28 |
|
| 29 | assert [x === $(pwd)]
|
| 30 | echo pass
|
| 31 |
|
| 32 | ## STDOUT:
|
| 33 | x=$
|
| 34 | pass
|
| 35 | ## END
|
| 36 |
|
| 37 | #### promptVal('w') respects ENV.HOME
|
| 38 |
|
| 39 | # ENV not set in spec tests
|
| 40 | var x = io.promptVal('w')
|
| 41 | assert [x.startsWith('/')]
|
| 42 |
|
| 43 | # now set it
|
| 44 | setglobal ENV.HOME = '/home'
|
| 45 |
|
| 46 | var x = io.promptVal('w')
|
| 47 | assert [x.startsWith('~')]
|
| 48 |
|
| 49 | ## STDOUT:
|
| 50 | ## END
|
| 51 |
|
| 52 | #### promptVal() with invalid chars
|
| 53 |
|
| 54 | # \D{} will be supported with date and time functions
|
| 55 | var x = io.promptVal('D')
|
| 56 | echo x=$x
|
| 57 |
|
| 58 | # something else
|
| 59 | var x = io.promptVal('/')
|
| 60 | echo x=$x
|
| 61 |
|
| 62 | var x = io.promptVal('ZZ')
|
| 63 | echo x=$x
|
| 64 |
|
| 65 | ## status: 3
|
| 66 | ## STDOUT:
|
| 67 | x=<Error: \D{} not in promptVal()>
|
| 68 | x=<Error: \/ is invalid or unimplemented in $PS1>
|
| 69 | ## END
|
| 70 |
|
| 71 |
|
| 72 | #### ysh respects PS1
|
| 73 |
|
| 74 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 75 | echo 'echo hi' | $[ENV.SH] -i
|
| 76 |
|
| 77 | ## STDOUT:
|
| 78 | hi
|
| 79 | ^D
|
| 80 | ## END
|
| 81 | ## stderr-json: "ysh myprompt$ ysh myprompt$ "
|
| 82 |
|
| 83 | #### ysh respects renderPrompt() over PS1
|
| 84 |
|
| 85 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 86 |
|
| 87 | cat >yshrc <<'EOF'
|
| 88 | func renderPrompt(io) {
|
| 89 | var parts = []
|
| 90 | call parts->append('hi')
|
| 91 | call parts->append(io.promptVal('$'))
|
| 92 | call parts->append(' ')
|
| 93 | return (join(parts))
|
| 94 | }
|
| 95 | EOF
|
| 96 |
|
| 97 | echo 'echo hi' | $[ENV.SH] -i --rcfile yshrc
|
| 98 |
|
| 99 | ## STDOUT:
|
| 100 | hi
|
| 101 | ^D
|
| 102 | ## END
|
| 103 | ## stderr-json: "hi$ hi$ "
|
| 104 |
|
| 105 | #### renderPrompt() doesn't return string
|
| 106 |
|
| 107 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 108 |
|
| 109 | cat >yshrc <<'EOF'
|
| 110 | func renderPrompt(io) {
|
| 111 | return ([42, 43])
|
| 112 | }
|
| 113 | EOF
|
| 114 |
|
| 115 | echo 'echo hi' | $[ENV.SH] -i --rcfile yshrc
|
| 116 |
|
| 117 | ## STDOUT:
|
| 118 | hi
|
| 119 | ^D
|
| 120 | ## END
|
| 121 | ## stderr-json: "<Error: renderPrompt() should return Str, got List> <Error: renderPrompt() should return Str, got List> "
|
| 122 |
|
| 123 |
|
| 124 | #### renderPrompt() raises error
|
| 125 |
|
| 126 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 127 |
|
| 128 | cat >yshrc <<'EOF'
|
| 129 | func renderPrompt(io) {
|
| 130 | error 'oops'
|
| 131 | }
|
| 132 | EOF
|
| 133 |
|
| 134 | echo 'echo hi' | $[ENV.SH] -i --rcfile yshrc
|
| 135 |
|
| 136 | ## STDOUT:
|
| 137 | hi
|
| 138 | ^D
|
| 139 | ## END
|
| 140 | ## stderr-json: "<Runtime error: oops><Runtime error: oops>"
|
| 141 |
|
| 142 |
|
| 143 | #### renderPrompt() has wrong signature
|
| 144 |
|
| 145 | setglobal ENV.PS1 = r'myprompt\$ '
|
| 146 |
|
| 147 | cat >yshrc <<'EOF'
|
| 148 | func renderPrompt() {
|
| 149 | error 'oops'
|
| 150 | }
|
| 151 | EOF
|
| 152 |
|
| 153 | echo 'echo hi' | $[ENV.SH] -i --rcfile yshrc
|
| 154 |
|
| 155 | ## STDOUT:
|
| 156 | hi
|
| 157 | ^D
|
| 158 | ## END
|
| 159 | ## stderr-json: "<Runtime error: Func 'renderPrompt' takes no positional args, but got 1><Runtime error: Func 'renderPrompt' takes no positional args, but got 1>"
|
| 160 |
|