babelfish

command module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2023 License: MIT Imports: 7 Imported by: 0

README

babelfish

Translate bash scripts to fish.

Why?

Because I got annoyed by having to use fish-foreign-env or bass, which are slow, since they create multiple bash processes. With this program I can translate bash scripts to fish, and run them directly in fish.

But how?

babelfish parses the script using mvdan.cc/sh, and then translates bash expressions to the equivalent fish code. That's it! You can find the code that walks the AST and emits fish code here.

Install

GO111MODULE=on go get bou.ke/babelfish

Example

# Pass some code on stdin to translate it
$ echo 'f() { export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket); local cool=yep; }' | babelfish
function f
  set -gx SSH_AUTH_SOCK (gpgconf --list-dirs agent-ssh-socket | string collect; or echo)
  set -l cool 'yep'
end
# Pass the result to source to load it into fish
$ echo 'echo Nice to meet you user $UID' | babelfish | source
Nice to meet you user 502
# Or install the shell hook!
$ source babel.fish
$ source chruby.sh
$ chruby
   ruby-2.5
   ruby-2.6
   ruby-2.7

To do

Probably still a lot. There's a couple variables like $BASH_SOURCE that aren't translated, and not all arithmetic expressions are implemented either. Pull requests and issues welcome!

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL