Shell-Session: Improvements (#2208) - Added support for elevated shells starting commands with `#` instead of `$`. - The user and cwd info `bash` and `sh` print before the interactive shell will now be highlighted. - Changed the line ends of test files to CRLF.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
diff --git a/components/prism-shell-session.js b/components/prism-shell-session.js
index 893fdb2..8abbd62 100644
--- a/components/prism-shell-session.js
+++ b/components/prism-shell-session.js
@@ -18,25 +18,37 @@
].join('|');
Prism.languages['shell-session'] = {
+ 'info': {
+ // foo@bar:~/files$ exit
+ // foo@bar$ exit
+ pattern: /^(?:[^\r\n$#*!]+)(?=[$#])/m,
+ alias: 'punctuation',
+ inside: {
+ 'path': {
+ pattern: /(:)[\s\S]+/,
+ lookbehind: true
+ },
+ 'user': /^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?=:|$)/,
+ 'punctuation': /:/
+ }
+ },
'command': {
- pattern: RegExp(/\$(?:[^\r\n'"<]|<<str>>)+/.source.replace(/<<str>>/g, strings)),
+ pattern: RegExp(/[$#](?:[^\r\n'"<]|<<str>>)+/.source.replace(/<<str>>/g, strings)),
+ greedy: true,
inside: {
'bash': {
- pattern: /(\$\s*)[\s\S]+/,
+ pattern: /(^[$#]\s*)[\s\S]+/,
lookbehind: true,
alias: 'language-bash',
inside: Prism.languages.bash
},
- 'sh': {
- pattern: /^\$/,
+ 'shell-symbol': {
+ pattern: /^[$#]/,
alias: 'important'
}
}
},
- 'output': {
- pattern: /.(?:.*(?:\r\n?|\n|.$))*/
- // output highlighting?
- }
+ 'output': /.(?:.*(?:\r\n?|\n|.$))*/
};
}(Prism));
diff --git a/components/prism-shell-session.min.js b/components/prism-shell-session.min.js
index f7b9129..9bf45bc 100644
--- a/components/prism-shell-session.min.js
+++ b/components/prism-shell-session.min.js
@@ -1 +1 @@
-!function(s){var n=["([\"'])(?:\\\\[\\s\\S]|\\$\\([^)]+\\)|`[^`]+`|(?!\\1)[^\\\\])*\\1","<<-?\\s*(\\w+?)\\s*(?:\r?\n|\r)[\\s\\S]*?(?:\r?\n|\r)\\2","<<-?\\s*([\"'])(\\w+)\\3\\s*(?:\r?\n|\r)[\\s\\S]*?(?:\r?\n|\r)\\4"].join("|");s.languages["shell-session"]={command:{pattern:RegExp("\\$(?:[^\r\\n'\"<]|<<str>>)+".replace(/<<str>>/g,n)),inside:{bash:{pattern:/(\$\s*)[\s\S]+/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},sh:{pattern:/^\$/,alias:"important"}}},output:{pattern:/.(?:.*(?:\r\n?|\n|.$))*/}}}(Prism);
\ No newline at end of file
+!function(s){var n=["([\"'])(?:\\\\[\\s\\S]|\\$\\([^)]+\\)|`[^`]+`|(?!\\1)[^\\\\])*\\1","<<-?\\s*(\\w+?)\\s*(?:\r?\n|\r)[\\s\\S]*?(?:\r?\n|\r)\\2","<<-?\\s*([\"'])(\\w+)\\3\\s*(?:\r?\n|\r)[\\s\\S]*?(?:\r?\n|\r)\\4"].join("|");s.languages["shell-session"]={info:{pattern:/^(?:[^\r\n$#*!]+)(?=[$#])/m,alias:"punctuation",inside:{path:{pattern:/(:)[\s\S]+/,lookbehind:!0},user:/^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?=:|$)/,punctuation:/:/}},command:{pattern:RegExp("[$#](?:[^\r\\n'\"<]|<<str>>)+".replace(/<<str>>/g,n)),greedy:!0,inside:{bash:{pattern:/(^[$#]\s*)[\s\S]+/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},"shell-symbol":{pattern:/^[$#]/,alias:"important"}}},output:/.(?:.*(?:\r\n?|\n|.$))*/}}(Prism);
\ No newline at end of file
diff --git a/examples/prism-shell-session.html b/examples/prism-shell-session.html
index 35501fe..07c9ce4 100644
--- a/examples/prism-shell-session.html
+++ b/examples/prism-shell-session.html
@@ -8,3 +8,11 @@ $ echo "Foo
> Bar"
Foo
Bar</code></pre>
+
+<p><code class="language-none">bash</code> and <code class="language-none">sh</code> console sessions are fully supported.</p>
+
+<pre><code>foo@bar:/$ cd ~
+foo@bar:~$ sudo -i
+[sudo] password for foo:
+root@bar:~# echo "hello!"
+hello!</code></pre>
diff --git a/tests/languages/shell-session/command_feature.test b/tests/languages/shell-session/command_feature.test
index 6a768e4..df721ee 100644
--- a/tests/languages/shell-session/command_feature.test
+++ b/tests/languages/shell-session/command_feature.test
@@ -1,31 +1,44 @@
-$ git checkout master
-Switched to branch 'master'
-Your branch is up-to-date with 'origin/master'.
-$ git push
-Everything up-to-date
-
-----------------------------------------------------
-
-[
- ["command", [
- ["sh", "$"],
- ["bash", [
- ["function", "git"],
- " checkout master"
- ]]
- ]],
- ["output", "Switched to branch 'master'\nYour branch is up-to-date with 'origin/master'.\n"],
-
- ["command", [
- ["sh", "$"],
- ["bash", [
- ["function", "git"],
- " push"
- ]]
- ]],
- ["output", "Everything up-to-date"]
-]
-
-----------------------------------------------------
-
-Checks for commands.
+$ git checkout master
+Switched to branch 'master'
+Your branch is up-to-date with 'origin/master'.
+$ git push
+Everything up-to-date
+# echo "root"
+root
+
+----------------------------------------------------
+
+[
+ ["command", [
+ ["shell-symbol", "$"],
+ ["bash", [
+ ["function", "git"],
+ " checkout master"
+ ]]
+ ]],
+ ["output", "Switched to branch 'master'\r\nYour branch is up-to-date with 'origin/master'.\r\n"],
+
+ ["command", [
+ ["shell-symbol", "$"],
+ ["bash", [
+ ["function", "git"],
+ " push"
+ ]]
+ ]],
+ ["output", "Everything up-to-date\r\n"],
+
+ ["command", [
+ ["shell-symbol", "#"],
+ ["bash", [
+ ["builtin", "echo"],
+ ["string", [
+ "\"root\""
+ ]]
+ ]]
+ ]],
+ ["output", "root"]
+]
+
+----------------------------------------------------
+
+Checks for commands.
diff --git a/tests/languages/shell-session/command_string_feature.test b/tests/languages/shell-session/command_string_feature.test
index d84afec..95a1219 100644
--- a/tests/languages/shell-session/command_string_feature.test
+++ b/tests/languages/shell-session/command_string_feature.test
@@ -1,66 +1,66 @@
-$ echo 'Foo
-> Bar'
-$ echo "Foo
-> Bar"
-
-$ echo <<- STRING_END
-foo
-bar
-STRING_END
-
-$ echo <<- "STRING_END"
-foo
-bar
-STRING_END
-
-----------------------------------------------------
-
-[
- ["command", [
- ["sh", "$"],
- ["bash", [
- ["builtin", "echo"],
- ["string", [
- "'Foo\n> Bar'"
- ]]
- ]]
- ]],
-
- ["command", [
- ["sh", "$"],
- ["bash", [
- ["builtin", "echo"],
- ["string", [
- "\"Foo\n> Bar\""
- ]]
- ]]
- ]],
-
- ["command", [
- ["sh", "$"],
- ["bash", [
- ["builtin", "echo"],
- ["operator", [
- "<<-"
- ]],
- ["string", [
- "STRING_END\nfoo\nbar\nSTRING_END"
- ]]
- ]]
- ]],
-
- ["command", [
- ["sh", "$"],
- ["bash", [
- ["builtin", "echo"],
- ["operator", [
- "<<-"
- ]],
- ["string", "\"STRING_END\"\nfoo\nbar\nSTRING_END"]
- ]]
- ]]
-]
-
-----------------------------------------------------
-
-Checks for multi-line strings inside commands.
+$ echo 'Foo
+> Bar'
+$ echo "Foo
+> Bar"
+
+$ echo <<- STRING_END
+foo
+bar
+STRING_END
+
+$ echo <<- "STRING_END"
+foo
+bar
+STRING_END
+
+----------------------------------------------------
+
+[
+ ["command", [
+ ["shell-symbol", "$"],
+ ["bash", [
+ ["builtin", "echo"],
+ ["string", [
+ "'Foo\r\n> Bar'"
+ ]]
+ ]]
+ ]],
+
+ ["command", [
+ ["shell-symbol", "$"],
+ ["bash", [
+ ["builtin", "echo"],
+ ["string", [
+ "\"Foo\r\n> Bar\""
+ ]]
+ ]]
+ ]],
+
+ ["command", [
+ ["shell-symbol", "$"],
+ ["bash", [
+ ["builtin", "echo"],
+ ["operator", [
+ "<<-"
+ ]],
+ ["string", [
+ "STRING_END\r\nfoo\r\nbar\r\nSTRING_END"
+ ]]
+ ]]
+ ]],
+
+ ["command", [
+ ["shell-symbol", "$"],
+ ["bash", [
+ ["builtin", "echo"],
+ ["operator", [
+ "<<-"
+ ]],
+ ["string", "\"STRING_END\"\r\nfoo\r\nbar\r\nSTRING_END"]
+ ]]
+ ]]
+]
+
+----------------------------------------------------
+
+Checks for multi-line strings inside commands.
diff --git a/tests/languages/shell-session/info_feature.test b/tests/languages/shell-session/info_feature.test
new file mode 100644
index 0000000..446c8b3
--- /dev/null
+++ b/tests/languages/shell-session/info_feature.test
@@ -0,0 +1,68 @@
+foo@bar:/var/local$ cd ~
+foo@bar:~$ sudo -i
+[sudo] password for foo:
+root@bar:~# echo "hello!"
+hello!
+
+foo@bar$ exit
+
+----------------------------------------------------
+
+[
+ ["info", [
+ ["user", "foo@bar"],
+ ["punctuation", ":"],
+ ["path", "/var/local"]
+ ]],
+ ["command", [
+ ["shell-symbol", "$"],
+ ["bash", [
+ ["builtin", "cd"],
+ " ~"
+ ]]
+ ]],
+
+ ["info", [
+ ["user", "foo@bar"],
+ ["punctuation", ":"],
+ ["path", "~"]
+ ]],
+ ["command", [
+ ["shell-symbol", "$"],
+ ["bash", [
+ ["function", "sudo"],
+ " -i"
+ ]]
+ ]],
+ ["output", "[sudo] password for foo:\r\n"],
+
+ ["info", [
+ ["user", "root@bar"],
+ ["punctuation", ":"],
+ ["path", "~"]
+ ]],
+ ["command", [
+ ["shell-symbol", "#"],
+ ["bash", [
+ ["builtin", "echo"],
+ ["string", [
+ "\"hello!\""
+ ]]
+ ]]
+ ]],
+ ["output", "hello!\r\n\r\n"],
+
+ ["info", [
+ ["user", "foo@bar"]
+ ]],
+ ["command", [
+ ["shell-symbol", "$"],
+ ["bash", [
+ ["builtin", "exit"]
+ ]]
+ ]]
+]
+
+----------------------------------------------------
+
+Checks for the info bash outputs.