diff options
author | Jose Antonio Marquez | 2012-07-17 14:01:12 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-07-17 14:01:12 -0700 |
commit | f40c8c58638da8fcd9a7abb06b8f2a4c6ba995bd (patch) | |
tree | cb1ff6a31b144fe4f584f778d5691f06362b227e /imports/codemirror/mode/shell | |
parent | 17d464e5bd224cdd8940855409359b411325f1df (diff) | |
parent | 4f737b24c19ddc02d20f9783b8b080fc6ef11142 (diff) | |
download | ninja-f40c8c58638da8fcd9a7abb06b8f2a4c6ba995bd.tar.gz |
Merge branch 'refs/heads/Ninja-Master' into Document
Diffstat (limited to 'imports/codemirror/mode/shell')
-rw-r--r-- | imports/codemirror/mode/shell/index.html | 50 | ||||
-rw-r--r-- | imports/codemirror/mode/shell/shell.js | 103 |
2 files changed, 153 insertions, 0 deletions
diff --git a/imports/codemirror/mode/shell/index.html b/imports/codemirror/mode/shell/index.html new file mode 100644 index 00000000..2d6d0847 --- /dev/null +++ b/imports/codemirror/mode/shell/index.html | |||
@@ -0,0 +1,50 @@ | |||
1 | <!doctype html> | ||
2 | <meta charset=utf-8> | ||
3 | <title>CodeMirror: Shell mode</title> | ||
4 | |||
5 | <link rel=stylesheet href=../../lib/codemirror.css> | ||
6 | <link rel=stylesheet href=../../doc/docs.css> | ||
7 | |||
8 | <style type=text/css> | ||
9 | .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;} | ||
10 | </style> | ||
11 | |||
12 | <script src=../../lib/codemirror.js></script> | ||
13 | <script src=shell.js></script> | ||
14 | |||
15 | <h1>CodeMirror: Shell mode</h1> | ||
16 | |||
17 | <textarea id=code> | ||
18 | #!/bin/bash | ||
19 | |||
20 | # clone the repository | ||
21 | git clone http://github.com/garden/tree | ||
22 | |||
23 | # generate HTTPS credentials | ||
24 | cd tree | ||
25 | openssl genrsa -aes256 -out https.key 1024 | ||
26 | openssl req -new -nodes -key https.key -out https.csr | ||
27 | openssl x509 -req -days 365 -in https.csr -signkey https.key -out https.crt | ||
28 | cp https.key{,.orig} | ||
29 | openssl rsa -in https.key.orig -out https.key | ||
30 | |||
31 | # start the server in HTTPS mode | ||
32 | cd web | ||
33 | sudo node ../server.js 443 'yes' >> ../node.log & | ||
34 | |||
35 | # here is how to stop the server | ||
36 | for pid in `ps aux | grep 'node ../server.js' | awk '{print $2}'` ; do | ||
37 | sudo kill -9 $pid 2> /dev/null | ||
38 | done | ||
39 | |||
40 | exit 0</textarea> | ||
41 | |||
42 | <script> | ||
43 | var editor = CodeMirror.fromTextArea(document.getElementById('code'), { | ||
44 | mode: 'shell', | ||
45 | lineNumbers: true, | ||
46 | matchBrackets: true | ||
47 | }); | ||
48 | </script> | ||
49 | |||
50 | <p><strong>MIME types defined:</strong> <code>text/x-sh</code>.</p> | ||
diff --git a/imports/codemirror/mode/shell/shell.js b/imports/codemirror/mode/shell/shell.js new file mode 100644 index 00000000..dddca867 --- /dev/null +++ b/imports/codemirror/mode/shell/shell.js | |||
@@ -0,0 +1,103 @@ | |||
1 | CodeMirror.defineMode('shell', function(config) { | ||
2 | |||
3 | var atoms = ['true','false'], | ||
4 | keywords = ['if','then','do','else','elif','while','until','for','in','esac','fi','fin','fil','done','exit','set','unset','export','function'], | ||
5 | commands = ['ab','awk','bash','beep','cat','cc','cd','chown','chmod','chroot','clear','cp','curl','cut','diff','echo','find','gawk','gcc','get','git','grep','kill','killall','ls','make','mkdir','openssl','mv','nc','node','npm','ping','ps','restart','rm','rmdir','sed','service','sh','shopt','shred','source','sort','sleep','ssh','start','stop','su','sudo','tee','telnet','top','touch','vi','vim','wall','wc','wget','who','write','yes','zsh']; | ||
6 | |||
7 | function tokenBase(stream, state) { | ||
8 | |||
9 | var sol = stream.sol(); | ||
10 | var ch = stream.next(); | ||
11 | |||
12 | if (ch === '\'' || ch === '"' || ch === '`') { | ||
13 | state.tokens.unshift(tokenString(ch)); | ||
14 | return tokenize(stream, state); | ||
15 | } | ||
16 | if (ch === '#') { | ||
17 | if (sol && stream.eat('!')) { | ||
18 | stream.skipToEnd(); | ||
19 | return 'meta'; // 'comment'? | ||
20 | } | ||
21 | stream.skipToEnd(); | ||
22 | return 'comment'; | ||
23 | } | ||
24 | if (ch === '$') { | ||
25 | state.tokens.unshift(tokenDollar); | ||
26 | return tokenize(stream, state); | ||
27 | } | ||
28 | if (ch === '+' || ch === '=') { | ||
29 | return 'operator'; | ||
30 | } | ||
31 | if (ch === '-') { | ||
32 | stream.eat('-'); | ||
33 | stream.eatWhile(/\w/); | ||
34 | return 'attribute'; | ||
35 | } | ||
36 | if (/\d/.test(ch)) { | ||
37 | stream.eatWhile(/\d/); | ||
38 | if(!/\w/.test(stream.peek())) { | ||
39 | return 'number'; | ||
40 | } | ||
41 | } | ||
42 | stream.eatWhile(/\w/); | ||
43 | var cur = stream.current(); | ||
44 | if (stream.peek() === '=' && /\w+/.test(cur)) return 'def'; | ||
45 | if (atoms.indexOf(cur) !== -1) return 'atom'; | ||
46 | if (commands.indexOf(cur) !== -1) return 'builtin'; | ||
47 | if (keywords.indexOf(cur) !== -1) return 'keyword'; | ||
48 | return 'word'; | ||
49 | } | ||
50 | |||
51 | function tokenString(quote) { | ||
52 | return function(stream, state) { | ||
53 | var next, end = false, escaped = false; | ||
54 | while ((next = stream.next()) != null) { | ||
55 | if (next === quote && !escaped) { | ||
56 | end = true; | ||
57 | break; | ||
58 | } | ||
59 | if (next === '$' && !escaped && quote !== '\'') { | ||
60 | escaped = true; | ||
61 | stream.backUp(1); | ||
62 | state.tokens.unshift(tokenDollar); | ||
63 | break; | ||
64 | } | ||
65 | escaped = !escaped && next === '\\'; | ||
66 | } | ||
67 | if (end || !escaped) { | ||
68 | state.tokens.shift(); | ||
69 | } | ||
70 | return (quote === '`' || quote === ')' ? 'quote' : 'string'); | ||
71 | }; | ||
72 | }; | ||
73 | |||
74 | var tokenDollar = function(stream, state) { | ||
75 | if (state.tokens.length > 1) stream.eat('$'); | ||
76 | var ch = stream.next(), hungry = /\w/; | ||
77 | if (ch === '{') hungry = /[^}]/; | ||
78 | if (ch === '(') { | ||
79 | state.tokens[0] = tokenString(')'); | ||
80 | return tokenize(stream, state); | ||
81 | } | ||
82 | if (!/\d/.test(ch)) { | ||
83 | stream.eatWhile(hungry); | ||
84 | stream.eat('}'); | ||
85 | } | ||
86 | state.tokens.shift(); | ||
87 | return 'def'; | ||
88 | }; | ||
89 | |||
90 | function tokenize(stream, state) { | ||
91 | return (state.tokens[0] || tokenBase) (stream, state); | ||
92 | }; | ||
93 | |||
94 | return { | ||
95 | startState: function() {return {tokens:[]}}, | ||
96 | token: function(stream, state) { | ||
97 | if (stream.eatSpace()) return null; | ||
98 | return tokenize(stream, state); | ||
99 | } | ||
100 | }; | ||
101 | }); | ||
102 | |||
103 | CodeMirror.defineMIME('text/x-sh', 'shell'); | ||