@@ -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
@@ -237,6 +241,8 @@ switch
237241# - __^C__: Cancel input if any. Quit otherwise.
238242# - __??__: <https://github.com/joyent/node/blob/master/lib/readline.js>
239243!function repl
244+ MAX -HISTORY -SIZE = 500
245+ history -file = path .join process .env.HOME, '/.lsc_history'
240246 code = if repl .infunc then ' ' else ''
241247 cont = 0
242248 rl = require 'readline' .create-interface process .stdin, process .stdout
@@ -251,6 +257,7 @@ switch
251257 _tty -write ...
252258 prompt = 'ls'
253259 prompt += " -#that" if 'b' * !!o .bare + 'c' * !!o .compile
260+ try rl .history = lines <| fs .read-file -sync history -file , 'utf-8' .trim!
254261 LiveScript .history = rl .history if LiveScript ?
255262 unless o .compile
256263 module .paths = module .constructor._node-module -paths \
@@ -309,7 +316,11 @@ switch
309316 catch then say e
310317 reset!
311318 process.on 'uncaughtException' !-> say " \n #{ it?stack or it }"
312- process .on 'exit' !-> rl ._tty-write '\r ' if code and rl .output.is -TTY
319+ process .on 'exit' !->
320+ rl ._tty-write '\r ' if code and rl .output.is -TTY
321+ if file -exists history -file
322+ (unlines . take MAX -HISTORY -SIZE ) rl .history
323+ |> fs .write-file -sync history -file , _
313324 rl .set-prompt "#prompt> "
314325 rl .prompt!
315326
0 commit comments