Show HN: Call Bash/ZSH/POSIX shell functions and built-ins from Fish

by dljsjron 7/31/2024, 4:01 PMwith 0 comments

Wanted to share a little tool I made that I'm calling `pisciform.fish`, heavily inspired by replay.fish[1] and bass.fish[2], but with a bit more oomph.

The tool allows you to create a fish function that mirrors a function definition from another shell. Because a shell function can mutate the calling environment (similar to using `source` on a shell script), the main mechanic of the wrapper is to look for environment mutations and play them back in the calling fish shell. This technique for bridging the different shell environments is inspired by replay and bass, but there are some slight differences.

The README for the repo provides a more detailed overview, including a more detailed explanation of how this tool differs from what already exists.

My motivation for making this is the fact that I've wanted to move over to `fish` for years for personal preference, but I was held back by a handful of things:

1. I like to create and share shell tools with my teams in professional settings, and getting a whole team to move to `fish` is likely a non-starter; plus, POSIX or Bash or ZSH are the lingua franca of shell scripting (short of Python).

2. While a shell script with a shebang is already portable, I prefer writing shell functions over writing shell scripts when feasible for a variety of reasons.

3. I'm coming from ZSH, where both replay and bass only speak Bash.

4. Most of the ZSH tools that I've written over the years are autoloadable function files, which can't just be `source`'d.

5. These are sometimes complicated tools that do more than just export variables, which bass and replay are more oriented towards. I needed to be able to run arbitrary commands, support interactivity, etc.

---

[1]: https://github.com/edc/bass

[2]: https://github.com/jorgebucaran/replay.fish

0