Why Sponsor Oils? | blog | oilshell.org

Interactive Shell Screencasts

2023-12-21

Pictures are worth more than words! This post shows off what OSH can do as an interactive shell.

A main theme is bridging old and new:

This work was large part of our second NLnet grant. Good news: we received a third grant and are looking for new contributors.

Table of Contents
Warmup: osh -n dumps the guts of Oils
Bridging Old and New
Running git-completion - ~3700 lines of bash
Headless Protocol: Oils <=> web_shell
More Demos
Job Control - Many shells don't have it
Python's virtualenv
Why Was this Post Delayed?
YSH and the Interactive Shell are Converging
Summary
Appendix
Download Tarball (10 seconds)
Compile and Install (30 seconds)

Warmup: osh -n dumps the guts of Oils

I usually show this command to new users first, because otherwise OSH looks very much like bash! Passing the -n flag dumps the syntax tree for a shell snippet or file.

Transcript:

osh -n -c 'echo "hello $name"'

So you can see that OSH is a completely new shell implementation.

(OSH has been completely translated to fast C++, but YSH has not yet. We should eliminate this issue in 2024, so users don't have to think about it.)

Bridging Old and New

Running git-completion - ~3700 lines of bash

Let's look at a large bash program that OSH can run.

When you hit TAB, we run the hooks in git-completion.bash, which is over 3700 lines of bash, maintained by the git team.

It now works in fast C++! Contributor Melvin Walls deserves the most credit for this. Late in 2022, he translated most of the interactive shell to C++, including tricky GNU readline bindings and interpreter signal handling.

(I've been using git-completion with the slow Python OSH for a few years. Again, we should eliminate the difference in 2024.)


Screencast transcript:

bash$ osh

$ wc -l ../git-completion
$ head ../git-completion
$ source ../git-completion

$ git checkout dev/andy
$ git log ..master

$ git <TAB>
$ git r<TAB>
$ git remote s<TAB>
$ git remote show <TAB>

Headless Protocol: Oils <=> web_shell

Now that we've seen that OSH is very compatible, here's something new.

This is a web_shell demo by Subhav Ramachandran (with contributions from Samuel Hierholzer), which I've mentioned posts tagged #headless.

Here are some docs on the headless shell protocol, which uses terminals over Unix domain sockets:

If you're building a terminal, you should support this protocol! I added compexport in Oils 0.18.0 so that the GUI can take over TAB completion.

Here's what the server prints while you interact with the UI:

Transcript:

cd ~/git/oilshell/oil
ls *.so
zzz
test/spec.sh smoke

The headless shell was kind of a side project ‐ not part of our NLnet grant.

But now I think it's one of the most unique capabilities of Oils. It's still raw, but can grow into something powerful.

More Demos

Let's look a few more interactive features.

Job Control - Many shells don't have it

Many shell users have Ctrl-Z and fg burned into their muscle memory, and OSH is one of few new shells to support it!

Melvin again did great work here, which I mentioned in the Oils 0.15.0 announcement back in May.

Transcript:

osh
vim hi.osh
echo 'hi'
Ctrl-Z
ls
osh hi.osh  # run the script we just created
fg
# and then another edit-run cycle

Python's virtualenv

Why should a new shell be POSIX compatible? Because a huge number of tools generate shell scripts, including Python's virtualenv.

osh  # do everything in OSH

python3 -m venv mypy.venv
. mypy.venv/bin/activate  # load generated shell into OSH

python3 -m pip install mypy  # install in virtualenv

python3 -c 'import mypy; print(mypy)'  # it's in the virtualenv

exit  # quit OSH

python3 -c 'import mypy'  # we're not in the virtualenv

Why Was this Post Delayed?

I mentioned these screencasts way back in September, in the announcement for Oils 0.18.0.

What have we been doing on since then? As mentioned in the recent Winter Status Update, we've been deep in the design of YSH — the shell language with data tYpes, influenced by pYthon.

That blog post has more details, including design decisions, philosophy, and links to new docs.

YSH and the Interactive Shell are Converging

This post mainly showed about OSH, not YSH.

We talk about YSH as a Python-like language more than a UI, but I've also said that a better shell language will enable better user interfaces. This is like Emacs being written mostly in Lisp, rather than C.

That idea is starting to become real with Oils 0.19.0, which I'll announce in the next post. In particular, the prompt hook is now a simple func that returns a string, rather than a dynamically-parsed $PS1 string like '$(some-command)${some_var} \d\$ '.

Summary

I showed that OSH is very compatible, and that it has new features like the headless protocol for GUIs.

And YSH is shaping up nicely, which you'll read about next.

If you got this far, you might be good person to work on Oils. It's 100% free and open source software, and you can even be paid to work on it.

Please ask questions in the Zulip comments, and feel to lurk and chime in on discussions!

I started a new #help-wanted channel with some concrete places to get started. And remember the Contributing wiki page is linked from our README.md.

Appendix

Here are a couple more screencasts, which show that Oils is easy to install.

Download Tarball (10 seconds)

Transcript:

wget 'https://www.oilshell.org/download/oils-for-unix-0.18.0.tar.gz'
ls -l -h  # source is just 429K

The tarball contains about 100K lines of pure C++. There's no more CPython code!

Compile and Install (30 seconds)

Transcript:

./configure
_build/oils.sh   # This shell script is generated
sudo ./install
osh -c 'echo hi'

Oils compiles with just a shell and a C++ compiler! No Make or CMake needed.