Ask coding questions

← Back to all posts
A Request to add Bash REPL customization with .bashrc
lutzhamel

The fact that you cannot customize Bash REPLs has been looked at many times in the 'Talk' forums. Just do a search on 'bashrc'. The fact that no proper solution has been proposed is kind of disappointing because without bash customization the Bash REPLS are kind of useless.

Case in point, I have attached a simple Bash REPL that introduces a new command 'hello' which I want to make available to the user in a seamless fashion by putting it into a project 'bin' directory and then adding that directory to the PATH. Even though this seems mundane and any interactive Unix/Linux process allows you to do that this is not possible in Bash REPLs.

Proposed solutions that don't work

Let's take a look at some of the solutions that have been proposed:

  1. "Put customization code into 'main.sh'" -- this does not work because 'main.sh' runs in a separate process from the actual Console/Shell processes and therefore any changes you make here will get lost as soon as the shell script exists.

  2. "Modify files above your project directory (REPL_SLUG)" -- this does not work either because the VM owns those those files and any modifications you make here are lost when you either start a new VM instance or fork your current VM.

  3. "Introduce custom env variables through secrets" -- that doesn't work either because the fact that I want to add 'bin' to the PATH variable is not a secret and should be carried to clones and instances started by other users which of course secrets don't do, leaving clones and new instances in a non-working state.

The only solution that reliably works in the current setting

The only solution to customizing Bash REPLS that currently reliably works across clones and new instances is sourcing the script that contains the customization code (see the REPL attached to this post). This is a not very satisfactory solution. Especially because a four line solution exists if the Bash REPL team were to implement it.

Suggested solution

Turns out the suggested solution is a four line modification to the script that sets up the Bash REPL Console/Shell environments. However, that fix needs to be done by the Bash REPL dev team so that it gets baked into the VM:

This fix looks into your top-level project directory to see if there is a .bashrc file there. If there is it includes the code as part of the regular setup for the Console/Shell environments.

Voters
lutzhamel