Commit graph

45 commits

Author SHA1 Message Date
Scott Olson 87e6649fc3 Fix handling of whitespace.
Whitespace will no longer be removed from input lines, which fixes pasting
multiline strings containing end-of-line or beginning-of-line whitespace.
2016-02-23 18:29:56 -06:00
Scott Olson 97da6d62f2 Print syntactially invalid attribute names as strings. 2016-02-20 01:14:22 -06:00
Eelco Dolstra a52fd0dbd0 Merge branch 'issue-13' of https://github.com/tsion/nix-repl 2016-02-18 19:40:27 +01:00
Scott Olson 56c7f0e8c5 Fix typo in comment. 2016-02-18 07:04:55 -06:00
Scott Olson 60ba98242f Fix recognition of REPL commands. 2016-02-18 06:59:51 -06:00
Scott Olson 64080d26fe Cancel multiline input on Ctrl-C. 2016-02-18 06:50:52 -06:00
Scott Olson 2d729e4f6f Support multiline input by detecting "unfinished" parse errors.
Fixes #4,
2016-02-18 06:27:39 -06:00
Scott Olson cfc874ee52 Open the store before constructing EvalState.
EvalState requires the `store` global to be initialized before it is constructed
in some cases, e.g. when it needs to download a tarball for something in
NIX_PATH. Hence, this fixes #13.
2016-02-16 18:40:47 -06:00
Scott Olson f30fd9c47b Don't consider empty strings or strings beginning with numbers as variable names. 2016-02-14 01:50:47 -06:00
Scott Olson 2111098a3a Don't consider strings starting with - or ' as variable names. 2016-02-14 01:29:48 -06:00
Scott Olson f7980b4712 Parse foo-bar = expr as an assignment. 2016-02-14 01:16:30 -06:00
Eelco Dolstra 8a2f5f0607 Fix building against Nix 1.10
Fixes #12.
2015-09-07 13:05:58 +02:00
Susan Potter 57aeef0b6a Fix nix-repl does not support '--help'
According to popular practice and convention `nix-repl` now supports `--help`
like a good POSIX citizen[1].

[1] https://www.gnu.org/prep/standards/html_node/Command_002dLine-Interfaces.html
2015-07-06 15:53:47 +02:00
Eelco Dolstra 45c6405a30 Fix building against latest Nix
Fixes #8.
Fixes #9.
2015-06-02 13:24:24 +02:00
Eelco Dolstra f92408136e Fix building against current Nix master 2014-12-01 10:07:10 +01:00
Eelco Dolstra 71d61508f2 Support -I flag 2014-08-26 20:05:08 +02:00
Eelco Dolstra 89f9c0d41b Fix building against current Nix master 2014-08-26 20:03:12 +02:00
Eelco Dolstra 02b66e97ba Fix building against current Nix master 2014-07-24 17:53:32 +02:00
Eelco Dolstra 66b2d18243 Don't parse 'var == expr' as an assignment 2014-06-16 10:05:09 -04:00
Eelco Dolstra 1734e8a149 Fix crash in tab completion
Fixes #1. Patch by Maxdamantus.
2014-04-11 12:51:15 +02:00
Eelco Dolstra 22a47ab03c Fix building against Nix 1.7 2014-04-11 12:50:46 +02:00
Eelco Dolstra 6a4a8208be Fix building against current Nix 2014-01-28 10:42:23 +01:00
Eelco Dolstra 3beb6f6e76 Show derivations more concisely 2014-01-28 10:42:23 +01:00
Eelco Dolstra dc670a173a Make tab-completion work on builtins 2013-09-09 17:22:42 +02:00
Eelco Dolstra e91160021f On reload, wipe the environment 2013-09-09 17:06:14 +02:00
Eelco Dolstra adde4f0c8d Add :reload command 2013-09-09 16:02:46 +02:00
Eelco Dolstra 3567bdb514 Add :quit command 2013-09-09 15:02:56 +02:00
Eelco Dolstra 3c67df928f Add sugar for defining a variable
‘x = <expr>’ is short for ‘:a { x = <expr>; }’.  Note that the
right-hand side refers to the original scope, so you get:

  nix-repl> x = 1
  nix-repl> x = x + 1
  nix-repl> x
  2

rather than an infinite recursion.
2013-09-09 13:56:53 +02:00
Eelco Dolstra 4b33c2dd4c Add help (:?) 2013-09-09 13:22:33 +02:00
Eelco Dolstra e133e91410 Support tab-completion on attribute sets
Example:

$ nix-repl '<nixos>'

> config.services.xserver.desktop<TAB>

comletes to

> config.services.xserver.desktopManager

You also get suggestions if there are multiple matches:

> config.services.xserver.desktopManager.kde4
config.services.xserver.desktopManager.kde4.enable
config.services.xserver.desktopManager.kde4.phononBackends
2013-09-09 12:00:33 +02:00
Eelco Dolstra 8e765b8876 printValue: Show assertion errors inline 2013-09-09 11:37:05 +02:00
Eelco Dolstra e587aec123 printValue: Don't show lists/attribute sets twice 2013-09-09 11:14:43 +02:00
Eelco Dolstra 7e3625f924 Improved value display
By default, we don't recurse into attribute sets or lists when
printing a value.  However, the new :p command does recurse.
2013-09-07 00:35:54 +02:00
Eelco Dolstra c6f2b89c0e Restore affinity 2013-09-06 21:00:36 +02:00
Eelco Dolstra 0abdf4beaa Add basic variable name completion 2013-09-06 19:51:59 +02:00
Eelco Dolstra cf4c29d90a Load files specified on the command line
For example:

  $ nix-repl '<nixpkgs>' '<nixos>'
  Welcome to Nix version 1.6pre3215_2c1ecf8. Type :? for help.

  Loading ‘<nixpkgs>’...
  Added 3337 variables.

  Loading ‘<nixos>’...
  Added 7 variables.

  nix-repl>
2013-09-06 15:20:06 +02:00
Eelco Dolstra b5944ac4ff Add a command :s to start a nix-shell for a derivation 2013-09-06 15:05:18 +02:00
Eelco Dolstra c6712a007f Add a command :b to build a derivation 2013-09-06 14:58:53 +02:00
Eelco Dolstra ad0dd359b4 Don't exit on SIGINT during evaluation
However, this may leave thunks in black-holed state, so it's not
really safe.
2013-09-06 13:20:35 +02:00
Eelco Dolstra 0b419c048b Use readline history file 2013-09-06 13:14:28 +02:00
Eelco Dolstra 4fb82d3d80 Handle SIGINT to cancel the current line 2013-09-06 13:01:02 +02:00
Eelco Dolstra 0f6279d874 Add a command :l for loading a file into scope
Example:

nix-repl> :l <nixpkgs>

nix-repl> lib.range 0 10
[ 0 1 2 3 4 5 6 7 8 9 10 ]

nix-repl> :l <nixos>

nix-repl> config.boot.kernelModules
[ "vboxdrv" "vboxnetadp" ... ]
2013-09-02 16:48:41 +00:00
Eelco Dolstra 3202206d1d Add a command :t for showing the type of an expression 2013-09-02 16:00:48 +00:00
Eelco Dolstra 287c88ca59 Support adding variables to the scope
The command ":a <expr>" evaluates <expr> and adds the attributes in
the resulting attribute set to the interpreter scope.  For instance:

nix-repl> :a import <nixpkgs> {}

nix-repl> lib.range 0 10
[ 0 1 2 3 4 5 6 7 8 9 10 ]
2013-09-02 17:53:58 +02:00
Eelco Dolstra e90569905e Initial version of nix-repl
This program interactively reads a Nix expression from the user,
evaluates it, and prints the result.
2013-09-02 15:18:15 +02:00