bash-seafly-prompt
bash-seafly-prompt copied to clipboard
A clean and fast Bash prompt
seafly is a modern, informative, and configurable command prompt for the Bash shell.
Inspiration provided by:
:rocket: For maximum performance, seafly will use, if available, the excellent gitstatus command.
Screenshot
The font in use is Iosevka.
Layout
seafly is a prompt that displays the following segments when using the default layout:
<Optional Prefix> <Optional User/Host> <Git Branch> <Git Indicators> <Current Path> <Prompt Symbol>
Note, when SEAFLY_LAYOUT=2
is set the prompt will instead display as:
<Optional Prefix> <Optional User/Host> <Current Path> <Git Branch> <Git Indicators> <Prompt Symbol>
seafly can also display as a multiline prompt when SEAFLY_MULTILINE=1
is
set. The layout will be the same as listed above but with additional newlines
prior to the prefix and prompt symbol.
Please refer to the configuration section below for more details.
Behaviour
-
When in a Git repository the checked out Git branch will be displayed.
-
When in a Git repository, dirty state, upstream and stash indicators will be displayed. Note, these can individually be disabled if desired.
-
The prompt symbol will change to an alert color, by default red, if the last command did not execute successfully.
Visuals
seafly by default will use Unicode characters for the prompt symbol and certain Git indicators. These symbols will display correctly when using a modern font such as Iosevka.
Also, seafly by default will use colors that favour a dark background.
Both the symbols and colors used by seafly can be overridden, please refer to the configuration section below. As an example, the following configuration will:
- only use ASCII characters
- use colors appropriate for a light terminal theme
- style the Git section to mimic
$(__git_ps1)
provided by thegit-prompt.sh
script that ships with Git
SEAFLY_PROMPT_SYMBOL=">"
SEAFLY_PS2_PROMPT_SYMBOL=">"
SEAFLY_GIT_PREFIX="("
SEAFLY_GIT_SUFFIX=")"
SEAFLY_GIT_DIRTY="*"
SEAFLY_GIT_STASH="$"
SEAFLY_GIT_AHEAD=">"
SEAFLY_GIT_BEHIND="<"
SEAFLY_GIT_DIVERGED="<>"
SEAFLY_NORMAL_COLOR="$(tput setaf 63)"
SEAFLY_ALERT_COLOR="$(tput setaf 202)"
SEAFLY_HOST_COLOR="$(tput setaf 242)"
SEAFLY_GIT_COLOR="$(tput setaf 99)"
SEAFLY_PATH_COLOR="$(tput setaf 70)"
. ~/.bash-seafly-prompt/command_prompt.bash
Requirements
A modern 256 or true color terminal is required.
Please also make sure the TERM
environment variable is set to
xterm-256color
, screen-256color
or equivalent terminal setting.
For example setting TERM
to xterm-256color
is usually done at the terminal
level either in a preferences dialog or a related configuration file, if
required at all. Note, some modern terminals will automatically set 256 colors
by default, for example, modern versions of Gnome
Terminal.
Setting TERM
to screen-256color
should only be done for
tmux sessions. If you are a tmux user then
please add the following to your ~/.tmux.conf
file:
set -g default-terminal "screen-256color"
set -ga terminal-overrides ',xterm-256color:Tc'
Note, modern terminals such as Alacritty and kitty provide their own terminfo definitions which are also supported by seafly prompt.
Installation
Install the seafly prompt script:
git clone --depth 1 https://github.com/bluz71/bash-seafly-prompt ~/.bash-seafly-prompt
Source the seafly prompt script in your ~/.bashrc
file:
. ~/.bash-seafly-prompt/command_prompt.bash
Note, to update to the latest version of seafly:
cd ~/.bash-seafly-prompt
git pull
gitstatus
The gitstatus command, a
high-performance alternative to the git status
command, is designed
specifically for low-latency command prompt usage.
The seafly prompt does not require gitstatus, but it is strongly
recommended to install and use this command, especially when dealing with large
Git repositories. Git detail collation will otherwise fallback to the slower
git
command when gitstatus is not available.
If possible, please install gitstatus:
git clone --depth 1 https://github.com/romkatv/gitstatus.git ~/.gitstatus
If gitstatus is already installed in an alternate directory then please export its location in an environment variable:
export SEAFLY_GITSTATUS_DIR=/location/of/gitstatus
Configuration
Certain behaviours and visuals of the seafly prompt can be controlled through environment variables.
Note, a dash character denotes an unset default value.
Behaviour
Option | Description | Default Value |
---|---|---|
SEAFLY_PRE_COMMAND |
A command to run each time the prompt is displayed. Please make sure any pre-command is very fast. For example, "history -a" . |
- |
SEAFLY_PROMPT_PREFIX |
A shell script snippet to populate the optional prefix segment. Please make sure the script snippet is simple and fast. Refer to the examples below. |
- |
SEAFLY_LAYOUT |
Specify the preferred layout. Layout 1 will display Git details followed by path.Layout 2 will flip the Git details and path. |
1 |
SEAFLY_MULTILINE |
Specify multiline layout.SEAFLY_MULTILINE=1 will display the prompt over multiple lines. |
0 |
SEAFLY_SHOW_USER |
Display the current user in the user/host segment. Set to 1 to display the user. |
0 |
SEAFLY_SHOW_HOST |
Display the current hostname in the user/host segment. Set to 0 to not display the host. |
1 |
PROMPT_DIRTRIM |
Shorten the current directory path to a set maximum number of components. Set to 0 to not shorten the current path. |
4 |
GIT_PS1_SHOWDIRTYSTATE |
Indicate the presence of Git modifications. Set to 0 to skip. |
1 |
GIT_PS1_SHOWSTASHSTATE |
Indicate the presence of Git stashes. Set to 0 to skip. |
1 |
GIT_PS1_SHOWUPSTREAM |
Indicate differences exist between HEAD and upstream in a Git remote-tracking branch. Set to 0 to skip. |
1 |
:gift: A few SEAFLY_PROMPT_PREFIX
examples:
-
When using the chruby Ruby version manager and when in a Ruby project base directory display the current Ruby version within parenthesis:
SEAFLY_PROMPT_PREFIX='if [[ -f Gemfile ]]; then echo "($(chruby | grep "*" | cut -d" " -f3))"; fi'
-
When in an active Python Virtual Environment display the name of the current environment within parenthesis:
SEAFLY_PROMPT_PREFIX='if [[ -n $VIRTUAL_ENV ]]; then echo "($(basename $VIRTUAL_ENV))"; fi'
-
When using the Node Version Manager display the name of the current JavaScript version within parenthesis:
SEAFLY_PROMPT_PREFIX='echo "($(nvm current))"'
:bomb: In certain Git repositories, calculating dirty-state can be slow,
either due to the size of the repository or the speed of the file-system
hosting the repository. If so, the prompt may render slowly. One can either
set GIT_PS1_SHOWDIRTYSTATE=0
to disable dirty-state indication for all
repositories, or if only a few repositories have performance issues then one
can do the following to skip dirty-state indication on a per-repository basis:
git config bash.showDirtyState false
:hourglass: The manyFiles
feature introduced in Git 2.24
may prove useful
to improve performance for very large repositories:
git config feature.manyFiles true
:rocket: Note, for best prompt rendering performance, when in Git repositories, please install and use the gitstatus command.
Symbols
Option | Description | Default Value |
---|---|---|
SEAFLY_PROMPT_SYMBOL |
The prompt symbol | ❯ |
SEAFLY_PS2_PROMPT_SYMBOL |
The PS2 secondary prompt symbol |
❯ |
SEAFLY_GIT_PREFIX |
Symbol to the left of the Git branch | - |
SEAFLY_GIT_SUFFIX |
Symbol to the right of the Git indicators | - |
SEAFLY_GIT_DIRTY |
Symbol indicating that a Git repository contains modifications | ✗ |
SEAFLY_GIT_STAGED |
Symbol indicating that a Git repository contains staged changes | ✓ |
SEAFLY_GIT_STASH |
Symbol indicating that a Git repository contains one or more stashes | ⚑ |
SEAFLY_GIT_AHEAD |
Symbol indicating that a Git remote-tracking branch is ahead of upstream | ↑ |
SEAFLY_GIT_BEHIND |
Symbol indicating that a Git remote-tracking branch is behind upstream | ↓ |
SEAFLY_GIT_DIVERGED |
Symbol indicating that a Git remote-tracking branch is both ahead and behind upstream | ↕ |
Colors
The default color values listed below, such as 111
and 203
, derive from
xterm 256 color values. Please refer to this
chart when customizing seafly colors.
Option | Description | Default Value | Color |
---|---|---|---|
SEAFLY_PREFIX_COLOR |
Optional prefix segment | $(tput setaf 153) |
|
SEAFLY_NORMAL_COLOR |
Normal prompt and certain Git indicators | $(tput setaf 111) |
|
SEAFLY_ALERT_COLOR |
Alert prompt and Git dirty indicator | $(tput setaf 203) |
|
SEAFLY_HOST_COLOR |
Host segment | $(tput setaf 255) |
|
SEAFLY_GIT_COLOR |
Git branch, stash and optional prefix/suffix | $(tput setaf 147) |
|
SEAFLY_PATH_COLOR |
Current directory path | $(tput setaf 150) |