Ask HN: Is there a Jupyter Notebook for terminal/shell

25 points by albert_e ↗ HN
When I learn new tools like Docker for example there are a number of new commands and syntax I am picking up along the way.

I want to "SAVE" my work -- the commands I used and the output I got -- as a "Notebook" similar to how we do for Python notebooks using Jupyter. Also add some markdown notes or links to reference material or tutorials I am following.

This allows me to revisit my work of yesterday / last month / last year and quickly review what I already "know" (or relearn quickly following the same path) and then go to next logical step.

Is there such a tool or solution?

Thanks in advance

20 comments

[ 3.3 ms ] story [ 56.1 ms ] thread
I've wondered this exact same thing almost every day for the last year—Alas! I am still wondering.
"kids these days huh" :)

You can save what you type with the 'script' command.

    script test_session
Will save everything you type and their output to the test_session file until you exit the shell with Ctrl-D

Look up "man script" for more details (funny it mentions 'typescript' but it is not that typescript)

(and while I joke about 'kids these days' I learned this from the UNIX greybeards so there's that as well)

This will not let you 'bookmark' selected commands which you can run later. I understand we can of course create aliases or small utility scripts, but having a place where we can just store these frequent commands is quite helpful especially with Docker, K8s or Azure/AWS CLI where commands are quite long to type and remember.
> I understand we can of course create aliases or small utility scripts, but having a place where we can just store these frequent commands

But that's exactly what an alias is. Put it on a script that you source when loading the terminal and there you have it

Or you could have a "commands.txt" where you copy/paste commands

Though yeah, maybe there should be a better solution (well, you can always look back history as well)

Thanks -- this is useful to know. Appreciate the pointer.

however, I am hoping for something that is far more interactively editable (like going up a couple of cells, editing and re running them in context) and also allows annotations / markdown / hyperlinks etc interspersed among the cells

PS: I am also on Windows a lot of time

You could use a jupyter notebook for this

Side-note: is the inverse of this available? E.g. open a jupyter notebook from in the middle of a python script

I use jupytext for this. For the cost of some header boilerplate I have python code that is seamlessly mirrored as a notebook.
I use VSCode and Markdown files. You can select anything and run that in the terminal by executing the action 'Terminal: Run Selected text in active terminal'

I have also given it a shortcut: `Ctrl+e, e`. So I can just select something and execute it in the terminal. Works quite well.

(Inspired by a similar feature in Emacs)

I would imagine emacs org mode probably has what you need
the new warp.dev terminal is kinda similar tho not exactly
emacs org mode will work in the terminal.

For example, in an org doc you can have something like this:

  * Python
  #+BEGIN_SRC python :results output
  def myTest(a):
   return a + 2
  
  print (myTest(8))
  #+END_SRC
  
  #+RESULTS:
  : 10
  
  #+BEGIN_SRC python :results output
  def check_even(n):
   if n % 2 == 0:
    print("even")
   else:
    print("odd")
  
  check_even(5)
  check_even(2)
  #+END_SRC
  
  #+RESULTS:
  : odd
  : even
You can run any command in the shell by prefixing them with ! In the jupyter cell. However I don‘t think jupyter notebooks are super useful for that usecase as you can’t simply double click to open them
Actually iPython started as a better Python shell, seems most people have forgotten these origins. The Jupyter notebook was born out of the same project and quickly replaced the shell as it obviously had much more possibilities for visualization and interactivity. If you have Jupyter installed you'll also have iPython. To run it, simply type

> ipython

You can use the %save magic command to save your session, there's lots more, check the documentation to discover it.

You may also use asciinema.org to record replayable tutorials. For adding notes, you can use a markdown file with the asciicast (the file format of asciinema) embedded.

Edit: But I do not know of an integrated, comfortable way to combine asciinema and markdown. Enhancing the asciicast format with (markdown) comments and make the asciicast players display them would be nice.

Yes! My project, euporie [1], is a TUI application for running and editing Jupyter notebooks in the terminal. It's interface similar to Jupyter Notebooks / Lab.

It sounds like exactly what you are after.

[1] https://github.com/joouha/euporie

A couple of suggestions:

- the xonsh (a full-featured unix shell, in python) kernel with jupyter

- the acme editor, using `win` to give you a dumb terminal access to your shell (or indeed any repl). As well as being a shell/repl, you can also treat that window as a text buffer, manipulating it and saving it as such (very liberating feeling, in practice)