Oil shell as an alternative shell script language in Kakoune

So I just gave this a spin, but it shows some promise.

There is oils.pub which provides osh, a posix compatible shell, which can be upgraded to ysh, which is a shell scripting language with data structures and more.

Since you can set the path to KAKOUNE_POSIX_SHELL, you can point it to osh instead.

KAKOUNE_POSIX_SHELL=/usr/bin/osh
kak # will now use osh

From there osh can be upgraded to use ysh within scripts

eval %sh {
  shopt --set ysh:upgrade
  var name = 'world'
  var d = {parts: ["hello", name]}
  echo "echo $[d.parts[0]]" # Will print hello, [1] prints name
}

Or

eval %sh{
  shopt --set ysh:upgrade
  proc print(str) { echo "echo $str" } 
  print "hello world"
}

It’s probably not a good idea as a lot of things that run POSIX sh code might break.

You can always cludge something together like Luar does and provide a ysh %{} command.

Ah yeah, it does seem that grep and make breaks with this setup. Though I am not sure entirely why :thinking:

That surprises me. I briefly tried Oil once a couple of years ago (it advertised better error messages and compatibility warnings that bash or dash) and found an issue with printf formatting that was quickly resolved — my understanding is they take bash compatibility quite seriously, and although the list of differences between bash’s defaults and POSIX is quite long, I don’t think most of those would affect Kakoune scripts.

If you can figure out why grep and make break, I’m sure they’d be interested in a bug report!

Yeah I might investigate it closer, as I suspect that it’s a bug given that oil shell aims to be posix complaint.

Interestingly it just doesn’t seem to play well with fifo. This also fails, it’s stuck:

eval %{
    fifo -name *test* %{
        echo hi
    }
}