Custom Bash Prompt in Intellij
Recently I wanted to change the prompt in the terminal when using IntelliJ. I have a development prompt that I like to use whenever I am developing and wanted IntelliJ to also use it.
If you just point the terminal in IntelliJ to a script that sets your prompt, it will not work. It simply runs that script and fails to open the terminal. There are a few solutions to the problem if you are using bash (thanks thrig!).
- Method 1: Running
bash --rcfile mycustomrc
will read whatever customizations you need from the given file. It may also be helpful to use the--login
or--noprofile
flags depending on whether you do or do not want themycustomrc
to mix with the standard shell settings. - Method 2: Use an environmental flag to determine whether or not to load the custom settings in the standard shell settings files.
- Method 3: Feed the custom shell configuration into a new
bash
process, then interact with it. See e.g.feed
,feed.1
,zcomppoke
,zcomppoke.1
for this pattern in action.
I choose method #1 since it was the simplest for what I wanted, and did not require me to add an environment variable before it would work.
To make this work, I had to set the terminal prompt as follows:
/bin/bash --rcfile ~/.dotfiles/dev_bashrc
That was all there is to it, the dev_bashrc is in my dotfiles repo on GitHub. It simply changes the prompt and loads as normal.