@@ -3,7 +3,7 @@ require! {
33 path
44 fs
55 util
6- 'prelude-ls' : {each , break -list }:prelude
6+ 'prelude-ls' : {each , break -list , lines , unlines , take }:prelude
77 './options' : {parse : parse -options , generate -help }
88 './util' : {name -from -path }
99 'source-map' : {SourceNode }
@@ -24,6 +24,10 @@ p = (...args) !->
2424pp = (x , show -hidden , depth ) !->
2525 say util .inspect x , show -hidden , depth , !process .env.NODE_DISABLE_COLORS
2626ppp = !-> pp it , true , null
27+ file -exists = (path ) ->
28+ try
29+ fs .stat-sync path
30+ true
2731
2832try
2933 o = parse -options args
@@ -246,6 +250,8 @@ function output-filename filename, json
246250# - __^C__: Cancel input if any. Quit otherwise.
247251# - __??__: <https://github.com/joyent/node/blob/master/lib/readline.js>
248252!function repl
253+ MAX -HISTORY -SIZE = 500
254+ history -file = path .join process .env.HOME, '/.lsc_history'
249255 code = if repl .infunc then ' ' else ''
250256 cont = 0
251257 rl = require 'readline' .create-interface process .stdin, process .stdout
@@ -260,6 +266,7 @@ function output-filename filename, json
260266 _tty -write ...
261267 prompt = 'ls'
262268 prompt += " -#that" if 'b' * !!o .bare + 'c' * !!o .compile
269+ try rl .history = lines <| fs .read-file -sync history -file , 'utf-8' .trim!
263270 LiveScript .history = rl .history if LiveScript ?
264271 unless o .compile
265272 module .paths = module .constructor._node-module -paths \
@@ -318,7 +325,11 @@ function output-filename filename, json
318325 catch then say e
319326 reset!
320327 process.on 'uncaughtException' !-> say " \n #{ it?stack or it }"
321- process .on 'exit' !-> rl ._tty-write '\r ' if code and rl .output.is -TTY
328+ process .on 'exit' !->
329+ rl ._tty-write '\r ' if code and rl .output.is -TTY
330+ if file -exists history -file
331+ (unlines . take MAX -HISTORY -SIZE ) rl .history
332+ |> fs .write-file -sync history -file , _
322333 rl .set-prompt "#prompt> "
323334 rl .prompt!
324335
0 commit comments