{"id":13593714,"url":"https://github.com/jonsequitur/dotnet-repl","last_synced_at":"2025-05-15T07:05:52.598Z","repository":{"id":40238534,"uuid":"355290536","full_name":"jonsequitur/dotnet-repl","owner":"jonsequitur","description":"A polyglot REPL built on .NET Interactive","archived":false,"fork":false,"pushed_at":"2025-03-10T21:52:36.000Z","size":260,"stargazers_count":768,"open_issues_count":32,"forks_count":36,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-04-10T06:24:38.649Z","etag":null,"topics":["dotnet","dotnet-interactive","repl"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonsequitur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-06T18:24:11.000Z","updated_at":"2025-04-09T16:03:56.000Z","dependencies_parsed_at":"2023-01-31T07:15:43.950Z","dependency_job_id":"386caad1-c761-4fab-b8af-7d22f8f70247","html_url":"https://github.com/jonsequitur/dotnet-repl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsequitur%2Fdotnet-repl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsequitur%2Fdotnet-repl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsequitur%2Fdotnet-repl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsequitur%2Fdotnet-repl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonsequitur","download_url":"https://codeload.github.com/jonsequitur/dotnet-repl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254292042,"owners_count":22046426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","dotnet-interactive","repl"],"created_at":"2024-08-01T16:01:23.541Z","updated_at":"2025-05-15T07:05:47.586Z","avatar_url":"https://github.com/jonsequitur.png","language":"C#","readme":"# dotnet-repl\n\n![REPL preview in C# and F#](https://user-images.githubusercontent.com/547415/121978422-02497600-cd3d-11eb-96c6-9725bda6dcaa.png)\n\nThis project is an experiment using [.NET Interactive / Polyglot Notebooks](https://github.com/dotnet/interactive) and [Spectre.Console](https://github.com/spectreconsole) to create a polyglot .NET REPL for use on the command line. \n\nThis is a personal project. Hopefully you enjoy it and find it useful. Contributions are welcome. \n\n[![NuGet Status](https://img.shields.io/nuget/v/dotnet-repl.svg?style=flat)](https://www.nuget.org/packages/dotnet-repl/) \n[![Build status](https://ci.appveyor.com/api/projects/status/j544mv4bxysjryru?svg=true)](https://ci.appveyor.com/project/jonsequitur/dotnet-repl)\n\n# Installation\n\nTo install `dotnet-repl`, run the following in your terminal:\n\n```console\n\u003e dotnet tool install -g dotnet-repl\n```\n\n# Features\n\nHere's what you can do with it:\n\n## *Code in C#*\n\nYou can start `dotnet-repl` in one of a number of different language modes. The default is C#, so the following two commands are equivalent:\n\n```console\n\u003e dotnet repl --default-kernel csharp\n\u003e dotnet repl\n```\n\nOnce the REPL has started, you can type C# code at the prompt and run it by pressing `Enter`. (Note that this is the [C# scripting](https://docs.microsoft.com/en-us/archive/msdn-magazine/2016/january/essential-net-csharp-scripting) dialect, which is also used in Visual Studio's C# Interactive Window and in .NET Interactive Notebooks.)\n\n\u003cimg src=\"https://user-images.githubusercontent.com/547415/121456759-68a85000-c95b-11eb-83a0-3b0010067e7b.png\" width=\"60%\" /\u003e\n\nOne notable feature of C# scripting is the ability to specify a return value for a code submission using a \"trailing expression\":\n\n\u003cimg src=\"https://user-images.githubusercontent.com/547415/121977410-d0cfab00-cd3a-11eb-84a0-ab4f8889c9c7.png\" width=\"60%\" /\u003e\n\n## *Code in F#*\n\nYou can also start up the REPL in F# mode with `--default-kernel` or set the environment variable `DOTNET_REPL_DEFAULT_KERNEL` to `fsharp`:\n\n```console\n\u003e dotnet repl --default-kernel fsharp\n```\n```console\n# DOTNET_REPL_DEFAULT_KERNEL=fsharp\n\u003e dotnet repl\n```\n\n\u003cimg src=\"https://user-images.githubusercontent.com/547415/121456837-8d9cc300-c95b-11eb-9a91-1daae2dbc655.png\" width=\"60%\" /\u003e\n\n## 📝 *Submit multi-line entries*\n\nBy pressing `Shift-Enter`, you can add multiple lines before running your code using `Enter`. This can be useful for creating multi-line code constructs, including declaring classes.\n\n\u003cimg src=\"https://user-images.githubusercontent.com/547415/121463971-dc505a00-c967-11eb-8a57-b976cc6b311b.png\" width=\"60%\" /\u003e\n\nAnother handy aspect of multi-line entries is that you no longer need to use the the F# Interactive convention of terminating a line with `;;` to indicate that the accumulated submission should be run. Pressing `Enter` will submit the code, and if you need more than one line of code at a time, you can use `Shift-Enter` to add lines before submitting.\n\n\u003cimg src=\"https://user-images.githubusercontent.com/547415/121977822-b5b16b00-cd3b-11eb-90d6-2798289a47d5.png\" width=\"60%\" /\u003e\n\n## 🚥 *Switch languages within the same session*\n\n\u003cimg src=\"https://user-images.githubusercontent.com/547415/121456913-ab6a2800-c95b-11eb-9a47-0f0828b2ba3b.png\" width=\"60%\" /\u003e\n\n## 🎁 *Add NuGet packages*\n\nYou can use `#r nuget` to install a package for the duration of the current session.\n\n\u003cimg src=\"https://user-images.githubusercontent.com/547415/121978012-235d9700-cd3c-11eb-89d0-ba367089208c.gif\" width=\"60%\" /\u003e\n\n\n## 🌱 *Initialize your REPL session using a notebook, script, or code file*\n\nYou can use a file containing code as an initialization script for the REPL.\n\n```console\n\u003e dotnet repl --run /path/to/notebook.ipynb\n```\n\nThe following file types are supported \n\n\u003cimg src=\"https://user-images.githubusercontent.com/547415/192895883-5e80e419-26dd-422c-b4bc-4d3533b861fb.gif\" width=\"60%\" /\u003e\n\n## 🏃🏽 *Run a notebook, script, or code file and then exit*\n\nYou might also want to just use a notebook or other file containing code as a non-interactive script. You can do this by adding the `--exit-after-run` flag. As long as the file extension indicates a language understood by .NET Interactive, it will try to run it.\n\n```console\n\u003e dotnet repl --run /path/to/notebook.ipynb --exit-after-run\n```\n\nFile formats currently supported are:\n\n* `.ipynb`: A Jupyter notebook, which can contain code cells in multiple different languages understood by .NET Interactive. \n* `.dib`: A .NET Interactive script file.\n* `.cs`: A C# source code file. (Some language constructs, such as namespaces, are not supported, so this one is extra experimental.)\n* `.csx`: A C# script file.\n* `.fs`: An F# source code file.\n* `.fsx`: An F# script file.\n* `.ps1`: A PowerShell script.\n* `.html`: An HTML file. (This will render in an external browser window.)\n* `.js`: A JavaScript file. (This will render in an external browser window.)\n\nIf all of the notebook's cells execute successfully, a `0` exit code is returned. Otherwise, `2` is returned. This can be used as a \nway to test notebooks. \n\n\u003cimg width=\"60%\" alt=\"image\" src=\"https://user-images.githubusercontent.com/547415/192914782-1c977e51-1715-40ca-9466-5ccc8219c23e.png\"\u003e\n\nIf you also want to capture the notebook output when it runs, you can do so by specifying the ` --output-path` and `--output-format` options. `--output-path` should be the file name you would like to write to. `--output-format` can be either `ipynb` or `trx`. `ipynb` is the default and will write a Jupyter notebook file with the outputs captured from the run. You can open this file using the [.NET Interactive Notebooks](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode) extension in Visual Studio Code, or any number of other Jupyter readers, and it can be displayed in GitHub. The `trx` format is a .NET test result file and can be useful in CI pipelines such as Azure DevOps, or can be opened with Visual Studio, or read with the [`t-rex`](https://www.nuget.org/packages/t-rex) tool.\n\n## 🛳️ *Import a notebook or script and run it*\n\nIf the REPL is already running, you can import a file into it and run it immediately using the `#!import` magic command. All of the same file types that `--run` supports are supported by `#!import`.\n\n## 🏀 Pass parameters when running a notebook or script\n\nIf a notebook contains magic commands with `@input` tokens, running them in a notebook editor like [.NET Interactive Notebooks](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode) will create a prompt for user input. Values for these inputs can provided on the command line using the `--input` option.\n\nFor example, let's say you have a notebook called `notebook.ipynb` containing the following magic commnand:\n\n```csharp\n#!connect mssql --kernel-name mydatabase @input:connectionString\n```\n\nYou can pass in the connection string from the command line like this:\n\n```console\n\u003e dotnet repl --run notebook.ipynb --input connectionString=\"Persist Security Info=False; Integrated Security=true; Initial Catalog=MyDatabase; Server=localhost\"\n```\n\n## 💁‍♀️ *Ask for help*\n\nYou can see help for the REPL by running the `#!help` magic command. I won't print it all here because it's a work in progress. Just give it a try.\n\n## ⌨ *Keyboard shortcuts*\n\n`dotnet-repl` supports a number of keyboard shortcuts. These will evolve over time but for now, here they are:\n\nKeybinding      | What it does                                                      |\n----------------|-------------------------------------------------------------------|\n`Enter`         | Submit and run the current code\n`Shift+Enter`   | Inserts a newline without submitting the current code\n`Tab`           | Show next completion\n`Shift+Tab`     | Show previous completion\n`Ctrl+C`        | Exit the REPL\n`Ctrl+Up`       | Go back through your submission history (current session only)\n`Ctrl+Down`     | Go forward through your submission history (current session only)\n\n\n## 🧙‍♂️ *Magic commands*\n\nBecause `dotnet-repl` is built on .NET Interactive, it supports \"magic commands\". You can recognize a magic command by the `#!` at the start of a line.\n\nYou can see the list of supported magic commands by running the `#!help` magic command.\n","funding_links":[],"categories":["C#","C\\#","Compilers, Transpilers and Languages"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonsequitur%2Fdotnet-repl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonsequitur%2Fdotnet-repl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonsequitur%2Fdotnet-repl/lists"}