3
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Io = require "luan:Io.luan"
|
95
|
4 local Site_translator = require "luan:ai/Site_translator.luan"
|
91
|
5 local get_lang = Site_translator.get_lang or error()
|
|
6 local text_writer = Site_translator.text_writer or error()
|
3
|
7 local Shared = require "site:/lib/Shared.luan"
|
|
8 local head = Shared.head or error()
|
|
9 local needed_header = Shared.needed_header or error()
|
91
|
10 local luan_url = Shared.luan_url or error()
|
3
|
11
|
|
12
|
|
13 return function()
|
91
|
14 Io.stdout = text_writer()
|
3
|
15 %>
|
|
16 <!doctype html>
|
91
|
17 <html lang="<%=get_lang()%>">
|
3
|
18 <head>
|
|
19 <% head() %>
|
109
|
20 <title>Reactionary Software - Better Shell</title>
|
15
|
21 </head>
|
3
|
22 <body>
|
|
23 <% needed_header() %>
|
|
24 <div content>
|
109
|
25 <h1>Better Shell</h1>
|
|
26
|
|
27 <p><a href="bash.html">Bash</a> is the shell that I recommend. But it is far from ideal. It is old and clunky and is cryptic for writing shell scripts. But since modern culture is incapaple of making anything good, you should stick with Bash. But in this post I will describe my fantasy shell that won't be implemented.</p>
|
|
28
|
|
29 <p>One thing that Bash gets right is conceptual simplicity. And a key part of that is being completely typeless. No need for types like booleans, numbers, maps, lists, etc. Just byte streams and strings, nothing more. <a href="https://en.wikipedia.org/wiki/Tcl">Tcl</a> is another language with typeless simplicity. But the implementation of Tcl evolved from first implementing everything as strings, and then later having <a href="https://wiki.tcl-lang.org/page/Tcl+data+types">a hidden internal type system</a>. An ideal shell would follow this example.</p>
|
3
|
30
|
109
|
31 <p>There should be 2 types: data and function. Data would be like in Bash - conceptually a byte stream or string. Functions should be like <a href="https://elv.sh/ref/language.html#function">Elvish functions</a>.</p>
|
|
32
|
|
33 <p>Output capture should be syntactically like Elvish as in <code>(echo hi)</code>, not like Bash as in <code>$(echo hi)</code>. Statements like <code>if</code>, <code>while</code>, etc should be implemented as built-in commands taking conditional arguments and function arguments like <a href="https://elv.sh/ref/language.html#if">in Elvish</a>. Conditional arguments should evaluate to the strings <code>"true"</code> or <code>"false"</code>. Any other value is an error. Numeric expressions should use the same command/prefix syntax as everything else, like in Elvish.</p>
|
|
34
|
|
35 <p>One nasty quirk of Bash is that with <code>whatever $(echo hello world)</code>, <code>whatever</code> gets passed 2 args "hello" and "world". For 1 arg, you must do <code>whatever "$(echo hello world)"</code>. Elvish gets this right and doesn't require quotes. My shell is the same, and <code>whatever (echo hello world)</code> would pass 1 arg "hello world".</p>
|
3
|
36
|
109
|
37 <p>There is no need for Bash's <code><</code>, <code>></code>, or <code>&</code>. Instead of <code>whatever <file</code> do <code>cat file | whatever</code>. Instead of <code>whatever >file</code> do <code>whatever | to file</code>. Instead of <code>whatever &</code> do <code>background {whatever}</code>. This is conceptually simpler.</p>
|
|
38
|
|
39 <p>Variables also don't deserve special treatments in a shell language. Instead of <code>NAME=Bob; echo $NAME</code> do <code>set NAME Bob; echo (get NAME)</code>. Don't tell me that this is too verbose. A shell language is not for writing big programs. And my way is conceptually simpler. It is also more flexible, allowing one to simulate arrays and maps like this:</p>
|
3
|
40
|
109
|
41 <code block>
|
|
42 set i 1
|
|
43 set a[(get i)] first
|
|
44 echo (get a[(get i)])
|
|
45 </code>
|
|
46
|
|
47 <p>Yes this is verbose. As Alan Kay said "Simple things should be simple; complex things should be possible.". This example is a complex thing for a shell.</p>
|
|
48
|
|
49 <p>I could go on, but you get the idea. Just show this page to any member of modern culture and see how much they hate it. That would be proof that this is a good idea. If you have an idea that would be even more hated than mine, then it would be a better idea. Anyway, no one is going to implement any of this. But this idea is at least an example of reactionary design.</p>
|
|
50
|
3
|
51 </div>
|
|
52 </body>
|
|
53 </html>
|
|
54 <%
|
|
55 end
|