0

Try to move to eshell and I am wondering what the best solution to translating the bash functions like below to eshell?


function cm-gen {
    cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON $@
    if [[ ! -e ./compile_commands.json && -e ./build/compile_commands.json ]]; then
        ln -s ./build/compile_commands.json .
    fi
}

1 Answer 1

1

Your best bet might be to take the meat of your function and place it into it's own non-eshell script; placing the script in a directory in your $PATH. If your command doesn't share a name with an eshell alias, eshell builtin, or emacs function; your script will be called.

From the Eshell manual:

Eshell looks first for an alias (see Aliases) with the same name as the command, then a built-in (see Built-in commands) or a function with the same name; if there is no match, it then tries to execute it as an external command.

If you are wondering what Emacs / Eshell considers an external command, I'm not sure of where a definitive answer lies (possibly esh-mode.el?). That said, Eshell can't use an external shell function directly (as in sourced from .bashrc or somesuch) because said functions are directly embedded in the external shell state and Eshell doesn't try to do any kind of gymnastics to pull said functions into Emacs state.

The safest naive definition, from my experience, is any command that exists in the external shell's $PATH.

Also check out this post from Mastering Emacs.

All that said...maybe I didn't really answer your question?

The way that you'd "translate a bash function into eshell" would be to translate the bash function into Elisp. Eshell is a shell written in Elisp living inside Emacs...so it's a specialized Elisp interpreter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.