MCPcopy Index your code
hub / github.com/bouk/babelfish

github.com/bouk/babelfish @v1.2.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.1 ↗ · + Follow
42 symbols 157 edges 4 files 2 documented · 5% 2 cross-repo links updated 17mo agov1.2.0 · 2023-06-19★ 2459 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
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!

Core symbols most depended-on inside this repo

str
called by 82
translate/translate.go
unsupported
called by 33
translate/err.go
printf
called by 24
translate/translate.go
word
called by 20
translate/translate.go
stmt
called by 11
translate/translate.go
body
called by 6
translate/translate.go
indent
called by 6
translate/translate.go
outdent
called by 6
translate/translate.go

Shape

Method 28
Function 10
Struct 3
TypeAlias 1

Languages

Go100%

Modules by API surface

translate/translate.go32 symbols
main.go4 symbols
translate/translate_test.go3 symbols
translate/err.go3 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add babelfish \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact