Termux – Custom Prompt

Termux is a terminal emulator and Linux environment for Android. I wanted to customise my prompt in the same way that I have done on my desktop/laptop machines. Ordinarily I would have a .bashrc in my home directory where I would make the changes to the prompt (PS1). However Termux doesn't recognise this.

I found a reference to configuring this: http://blog.ataboydesign.com/2015/12/01/termux-is-the-one-for-android/

Following this method the changes to PS1 are made in "/data/data/com.termux/files/usr/etc/bash.bashrc". I had been successfully using this method for a while with no ill effects. That was until today when I realised an update to Termux had overwritten the changes. Not what I wanted.

So after some searching I have found a solution that should survive future updates. In your Termux home directory save the following as ".profile". This will be run when Termux is started and make Termux look for a ".bashrc" file in the home directory.

# .profile
if [ -n "BASH_VERSION" ]; then
  # Echo msg to indicate file is run - can be removed later
  echo "Profile load.bashrc"
  # include .bashrc if it exists
  if [ -f "$HOME/.bashrc" ]; then
  . "$HOME/.bashrc"
  fi
fi

Create and edit ".bashrc" with any custom options. Exit and restart Termux and your custom configuration should be loaded.

Leave a Reply