Back to course

Customizing the Shell Prompt (PS1 variable)

Termux Masterclass: From Zero to Linux Power User on Android

34. Customizing the Shell Prompt (PS1 variable)

The shell prompt ($) is defined by the special variable PS1. Customizing it can improve readability and efficiency by showing key information (like Git status, time, etc.) at a glance.

The Default Termux Prompt

Termux often uses a simple prompt that shows the current user and directory.

Modifying PS1 Temporarily

You can change the prompt for the current session instantly by exporting a new value.

bash

\u = username, \h = hostname (Termux hostname is usually localhost), \w = basename of current directory

$ export PS1='[\e[1;36m]\u@termux:[\e[0m]\w$ '

Explanation of components:

  • \[\e[1;36m\]: Start bold, cyan color.
  • \u@termux:: Displays username and static text.
  • \[\e[0m\]: Reset color to default.
  • \w: Current directory basename.
  • $ : The final prompt symbol.

Making it Permanent

To make your customized prompt stick, you must add the export PS1='...' line to your ~/.bashrc file (or ~/.zshrc if using Zsh).

  1. Open .bashrc.
  2. Add your chosen export PS1=... line.
  3. source ~/.bashrc to activate.

Advanced Tip: Many users integrate Git status indicators into their PS1, allowing them to instantly see if they are on a clean branch or if changes are pending. This usually requires a custom function defined in the .bashrc.