Add and Remove Byobu's Timed Bash Prompt Safely
You will finish with Byobu's colour Bash prompt enabled, showing the previous command's approximate runtime and non-zero exit status, with a clean way to remove the change. These examples use the installed Byobu package version 6.11-0ubuntu1.1.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes. You need Byobu installed, Bash as your current shell, and a writable ~/.bashrc. The commands change your user shell configuration only. They do not need sudo, and using elevated privileges would target the wrong home directory in most cases.
1. Check the shell and installed version
The prompt helper is compatible with Bash, not with an arbitrary shell. Check both the shell selected for this session and the package version before changing anything:
$ printf 'shell: %s\n' "$SHELL"
shell: /bin/bash
$ command -v byobu-prompt byobu-enable-prompt byobu-disable-prompt
/usr/bin/byobu-prompt
/usr/bin/byobu-enable-prompt
/usr/bin/byobu-disable-prompt
$ dpkg-query -W -f='${Package} ${Version}\n' byobu
byobu 6.11-0ubuntu1.1
Checkpoint
Continue only if $SHELL is /bin/bash. The enable helper checks this variable exactly. A Bash shell started manually while $SHELL still names another shell can therefore be rejected; correct the session or use a normal Bash login before retrying.
2. Inspect the existing prompt line
Before enabling anything, look for a previous Byobu prompt entry. This is read-only and lets you spot a custom configuration that should be backed up first:
$ grep -nF '#byobu-prompt#' ~/.bashrc || echo 'no Byobu prompt line found'
no Byobu prompt line found
If the command prints a line, do not keep running the enable command to solve a duplicate. The helper writes a new marker line after removing its own older marker, but it does not understand unrelated prompt customisations. Copy the file before making a deliberate change:
$ cp --preserve=all ~/.bashrc ~/.bashrc.before-byobu-prompt
$ ls -l ~/.bashrc ~/.bashrc.before-byobu-prompt
That backup is your recovery point. It contains your personal shell settings, so keep its permissions and do not paste it into a public issue or chat.
3. Enable the prompt
Run the enable helper as your ordinary user:
$ byobu-enable-prompt
You will need to reload your shell configuration for this to take effect...
. ~/.bashrc
The installed helper creates or updates Byobu's user prompt file and appends a guarded source line ending in #byobu-prompt# to ~/.bashrc. It does not replace your whole Bash configuration. The user configuration directory is normally ~/.byobu when that directory already exists, otherwise Byobu follows XDG_CONFIG_HOME or uses ~/.config/byobu.
Reload the file in the current Bash process:
$ . ~/.bashrc
$ grep -nF '#byobu-prompt#' ~/.bashrc
N:[ -r .../byobu/prompt ] && . .../byobu/prompt #byobu-prompt#
The exact path and line number are host-specific. If you are inside a tmux session, this package version attempts to reload the configuration through tmux when enabling; an explicit . ~/.bashrc is still a clear verification step.
4. Verify timing and failure status
Run a short command and then a deliberately failing command. The prompt is interactive, so the bracketed timing text appears immediately before the next prompt rather than as ordinary command output:
$ sleep 1
[1.00Xs] andy@host:~/work$ false
[1] [0.00Xs] andy@host:~/work$
The runtime is approximate and its exact digits depend on scheduling. A non-zero status is shown when the previous command failed. The prompt also uses separate colours for the user, host and working directory, although terminal themes may make those colours look different. The prompt symbol is $ for a normal user and # for root.
Checkpoint
Do not mistake the timer for a benchmark. It measures the previous interactive command as observed by Byobu's Bash hooks. It does not measure shell startup, and it is not a substitute for a profiling tool.
5. Understand the Bash boundary
The prompt file uses Bash features, including PS0 and Bash's EPOCHREALTIME. Do not source it from Zsh, Dash or a script that is not running Bash. If a tool launches a non-interactive shell, its prompt may not be displayed even though the marker remains in ~/.bashrc.
If a new terminal shows no change, check the simple causes in order:
- Confirm that the new terminal is Bash with
printf '%s\n' "$0"andprintf '%s\n' "$SHELL". - Confirm that
~/.bashrccontains the marker line and that the referenced prompt file exists. - Run
. ~/.bashrcagain, then runtrueandfalseto create fresh prompt results.
If enabling exits with status 1, inspect the shell value and the write permission of the file:
$ printf 'shell=%s\n' "$SHELL"
$ test -w ~/.bashrc && echo 'bashrc writable' || echo 'bashrc is not writable'
$ printf 'status=%s\n' "$?"
Do not make ~/.bashrc writable by everyone just to get past this check. Fix ownership or permissions through your normal account-repair process, and preserve the backup made earlier.
6. Disable it and undo the change
When you no longer want the prompt, use the matching helper:
$ byobu-disable-prompt
You will need to reload your shell configuration for this to take effect...
. ~/.bashrc
$ . ~/.bashrc
$ grep -nF '#byobu-prompt#' ~/.bashrc || echo 'Byobu prompt disabled'
Byobu prompt disabled
Disable removes lines ending with the Byobu marker. It does not remove the rest of your Bash configuration. If you need to restore the exact pre-change state, stop first and compare the backup rather than overwriting blindly:
$ diff -u ~/.bashrc.before-byobu-prompt ~/.bashrc
$ cp --preserve=all ~/.bashrc.before-byobu-prompt ~/.bashrc
$ . ~/.bashrc
The final copy is a deliberate replacement of your current shell configuration. Use it only after reviewing the diff; any unrelated edits made after the backup will be lost. If you did not make a backup, disable the prompt and remove only a line that you have confirmed ends in #byobu-prompt#.
7. Use the interactive wrapper when preferred
byobu-prompt is an interactive wrapper around the enable and disable helpers. It asks a yes-or-no question; an empty answer or any answer other than n selects enable, while n or N selects disable:
$ byobu-prompt
Do you want to enable Byobu's bash color prompt? [Y/n]: n
You will need to reload your shell configuration for this to take effect...
. ~/.bashrc
For repeatable administration, the explicit commands are easier to audit. The wrapper still requires an interactive input stream, so it is a poor fit for an unattended script.
Done means
- Your session uses Bash and the installed Byobu package version is known.
~/.bashrccontains one intentional#byobu-prompt#entry when the feature is enabled.- A fresh Bash prompt shows approximate runtime, and a failed command shows its non-zero status.
- You know that the change is user-local and does not require root privileges.
byobu-disable-promptremoves the marked entry, and a reviewed backup can restore the earlier file.