All Projects → petobens → Trueline

petobens / Trueline

Licence: mit
Fast and extensible bash powerline prompt with true color and fancy icon support

Programming Languages

shell
77523 projects
bash
514 projects

Projects that are alternatives of or similar to Trueline

Prompt Checkbox
This repository has been archived, use Enquirer instead.
Stars: ✭ 21 (-92.25%)
Mutual labels:  terminal, prompt
Pure
Pretty, minimal and fast ZSH prompt
Stars: ✭ 10,891 (+3918.82%)
Mutual labels:  terminal, prompt
Termly.js
Simple, Extensible, Hackable and Lightweight Javascript Browser Terminal Simulator!
Stars: ✭ 56 (-79.34%)
Mutual labels:  terminal, prompt
Go Prompt
Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.
Stars: ✭ 4,255 (+1470.11%)
Mutual labels:  terminal, prompt
cmder-powershell-powerline-prompt
Custom PowerShell prompt for Cmder on Windows
Stars: ✭ 94 (-65.31%)
Mutual labels:  prompt, powerline
Typewritten
A minimal, lightweight, informative zsh prompt theme
Stars: ✭ 442 (+63.1%)
Mutual labels:  terminal, prompt
Sbt Prompt
An SBT plugin for making your SBT prompt more awesome
Stars: ✭ 107 (-60.52%)
Mutual labels:  terminal, powerline
Angel Ps1
Your fancy shell prompt fed by your guardian angel
Stars: ✭ 60 (-77.86%)
Mutual labels:  prompt, powerline
Spaceship Prompt
🚀⭐ A Zsh prompt for Astronauts
Stars: ✭ 15,748 (+5711.07%)
Mutual labels:  terminal, prompt
.tmux
🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️
Stars: ✭ 15,594 (+5654.24%)
Mutual labels:  terminal, powerline
Hues
Colored terminal text made easy for Python and happiness.
Stars: ✭ 345 (+27.31%)
Mutual labels:  terminal, powerline
powerless
Minimalistic/responsive ZSH prompt inspired by powerline.
Stars: ✭ 63 (-76.75%)
Mutual labels:  prompt, powerline
Silver
A cross-shell customizable powerline-like prompt with icons
Stars: ✭ 238 (-12.18%)
Mutual labels:  prompt, powerline
Dotfiles
Configurations for the tools I use every day
Stars: ✭ 898 (+231.37%)
Mutual labels:  terminal, prompt
Powerline
Powerline is a statusline plugin for vim, and provides statuslines and prompts for several other applications, including zsh, bash, tmux, IPython, Awesome and Qtile.
Stars: ✭ 12,989 (+4692.99%)
Mutual labels:  prompt, powerline
Tty Prompt
A beautiful and powerful interactive command line prompt
Stars: ✭ 1,210 (+346.49%)
Mutual labels:  terminal, prompt
Powerline
A more PowerShell prompt
Stars: ✭ 444 (+63.84%)
Mutual labels:  prompt, powerline
Powerline Extra Symbols
▶️ Extra glyphs for your powerline separators
Stars: ✭ 778 (+187.08%)
Mutual labels:  prompt, powerline
Fancy Git
That's a simple prompt changer to show a few cool git informations about your repository on terminal. You can choose among 13 styles and enjoy all the aliases it provides you. Feel free for contributing, pull requests and issues are always welcome! ;)
Stars: ✭ 123 (-54.61%)
Mutual labels:  terminal, prompt
fishline
A powerline prompt framework for the fish-shell built in fish-shell.
Stars: ✭ 66 (-75.65%)
Mutual labels:  prompt, powerline

Trueline: Bash Powerline Style Prompt with True Color Support

Trueline is a fast and extensible Powerline style bash prompt with true color (24-bit) and fancy glyph support.

The pure Bash code implementation and overall features are modelled after the excellent Pureline command prompt. However Trueline also adds the ability to use RGB color codes, expands icon/glyph usage across prompt segments (inspired by Powerlevel9k), simplifies configuration and, among other goodies, shows the current input mode (when in vi-mode).

Installation

Download the trueline.sh script in this repo and source it from within your .bashrc file:

$> git clone https://github.com/petobens/trueline ~/trueline
$> echo 'source ~/trueline/trueline.sh' >> ~/.bashrc

or alternatively

$> wget https://raw.githubusercontent.com/petobens/trueline/master/trueline.sh -P ~/
$> echo 'source ~/trueline.sh' >> ~/.bashrc

If you use a font that supports "Powerline" glyphs, such as those included in the wonderful Nerd Fonts project, then the prompt should render properly and no further configuration is necessary (as long as you like the default settings shown in the image above).

Customization

Customizing and extending the prompt is easy and there are several segment options available to do so.

All settings go inside your .bashrc and must be defined before actually sourcing the trueline.sh file (otherwise default settings will be used). To see how this works let's start with a simple configuration example:

declare -A TRUELINE_COLORS=(
    [light_blue]='75;161;207'
    [grey]='99;99;100'
    [pink]='199;88;157'
)

declare -a TRUELINE_SEGMENTS=(
    'working_dir,light_blue,black,normal'
    'git,grey,black,normal'
    'time,white,black,normal'
    'newline,pink,black,bold'
)

declare -A TRUELINE_SYMBOLS=(
    [git_modified]='*'
    [git_github]=''
    [segment_separator]=''
    [working_dir_folder]='...'
    [working_dir_separator]='/'
    [working_dir_home]='~'
    [newline]='❯'
    [clock]='🕒'
)

TRUELINE_GIT_SHOW_STATUS_NUMBERS=false
TRUELINE_GIT_MODIFIED_COLOR='grey'
TRUELINE_WORKING_DIR_SPACE_BETWEEN_PATH_SEPARATOR=false

_trueline_time_segment() {
    local prompt_time="${TRUELINE_SYMBOLS[clock]} \t"
    if [[ -n "$prompt_time" ]]; then
        local fg_color="$1"
        local bg_color="$2"
        local font_style="$3"
        local segment="$(_trueline_separator)"
        segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " $prompt_time ")"
        PS1+="$segment"
        _last_color=$bg_color
    fi
}

source ~/trueline/trueline.sh

which generates the following prompt (that essentially replicates the minimal ZSH Pure prompt):

You can see in the config above that there are basically 5 different/relevant settings: colors, segments, symbols, options and extensions. Let's break each of these down.

Colors

Colors are defined by means of an associative array named TRUELINE_COLORS. The keys of this array are color names and the values RGB color codes:

declare -A TRUELINE_COLORS=(
    [color_name]='red;green;blue'
)

Default colors are loosely based on Atom's One Dark theme and given by:

declare -A TRUELINE_COLORS=(
    [black]='36;39;46'
    [cursor_grey]='40;44;52'
    [green]='152;195;121'
    [grey]='171;178;191'
    [light_blue]='97;175;239'
    [mono]='130;137;151'
    [orange]='209;154;102'
    [purple]='198;120;221'
    [red]='224;108;117'
    [special_grey]='59;64;72'
    [white]='208;208;208'
)

Any TRUELINE_COLORS array defined in the bashrc file prior to sourcing the Trueline script will actually update the default array above (in the sense that it will overwrite existing keys and add non-existing ones). This basically means that default colors can always be used and the array only needs to be defined when new extra colors are truly needed.

Note: you can define any color name you want except for default_bg which is used by Trueline to obtain the default terminal background color.

Segments

Prompt segments are defined in an ordered array called TRUELINE_SEGMENTS that has the following structure:

declare -a TRUELINE_SEGMENTS=(
    'segment_name,segment_fg_color,segment_bg_color,font_style'
)

where the segment foreground and background color names are keys of the TRUELINE_COLORS array and the font style is either bold, dim, italic, normal or underlined. The order of the elements in the array define the order in which each segment is rendered in the prompt.

Trueline offers the following segments (status indicates whether they are enabled/rendered by default):

Segment Name Status Description
aws_profile enabled current AWS profile
bg_jobs enabled number of background jobs
cmd_duration disabled last command execution time
conda_env disabled current anaconda environment
exit_status enabled return code of last command
git enabled git branch/remote and repository status
newline disabled splits prompt segments across multiple lines
read_only enabled indicator of read only directory
user enabled username and host (conditional on ssh status)
venv enabled Python virtual environment
working_dir enabled current working directory

but more segments can be easily added (see Extensions).

To enable the newline segment one could use the following config:

declare -a TRUELINE_SEGMENTS=(
    'working_dir,mono,cursor_grey,normal'
    'git,grey,special_grey,normal'
    'newline,black,orange,bold'
)

which results in:

Symbols

Symbols (i.e icons/glyphs) are defined through an associative array named TRUELINE_SYMBOLS where each entry key is a (predefined) segment symbol name and the value is the actual symbol/icon:

declare -A TRUELINE_SYMBOLS=(
    [segment_symbol_name]='|' # actual symbol
)

The following table shows the current predefined symbol names along with their default values (i.e either the actual glyph or the corresponding nerd-font unicode code):

Symbol Name Glyph Symbol Name Glyph
aws_profile U+f52c ps2 ...
bg_jobs U+f085 read_only U+f023
exit_status blank segment_separator U+e0b0
git_ahead U+f55c ssh U+f817
git_behind U+f544 timer U+fa1e
git_bitbucket U+f171 venv (and conda) U+e73c
git_branch U+e0a0 vimode_cmd N
git_github U+f408 vimode_ins I
git_gitlab U+f296 working_dir_folder U+e5fe
git_modified U+f44d working_dir_home U+f015
newline U+f155 working_dir_separator U+e0b1
newline_root U+f52c

As with TRUELINE_COLORS, any TRUELINE_SYMBOLS array defined in the bashrc file prior to sourcing the Trueline script will actually update the array with the default symbols shown above (thus such array needs to be defined only when overriding some icon or adding new ones).

Options

Most Trueline settings are controlled with the 3 structures defined above. However Trueline also defines a series of variables that control some extra options. In particular we can distinguish between intra-segment and external options. These, along with their default values, are defined as follows:

Intra-segment

The next segments have (sub)settings of their own:

  • git:
    • TRUELINE_GIT_SHOW_STATUS_NUMBERS=true: boolean variable that determines whether to show (or not) the actual number of modified files and commits behind/ahead next to the corresponding modified-behind/ahead status symbol.
    • TRUELINE_GIT_MODIFIED_COLOR='red': foreground color for symbol and number of modified files.
    • TRUELINE_GIT_BEHIND_AHEAD_COLOR='purple': foreground color for symbol and number of commits behind/ahead.
  • user:
    • TRUELINE_USER_ROOT_COLORS=('black' 'red'): root user foreground and background colors.
    • TRUELINE_USER_SHOW_IP_SSH=false: boolean variable that determines whether to show the ip address or hostname in a ssh connection.
    • TRUELINE_USER_ALWAYS_SHOW_HOSTNAME=false: boolean variable that determines whether to always show the ip address or hostname (not just in a ssh connection).
  • working_dir:
    • TRUELINE_WORKING_DIR_SPACE_BETWEEN_PATH_SEPARATOR=true: boolean variable that determines whether to add (or not) a space before and after the path separator.
    • TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS=false: boolean variable that when set to true shows the full working directory (instead of trimming it). Each parent directory is shortened to TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS_LENGTH.
    • TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS_LENGTH=1: length of each parent directory when TRUELINE_WORKING_DIR_ABBREVIATE_PARENT_DIRS is enabled.

External

  • TRUELINE_SHOW_VIMODE=false: boolean variable that determines whether or not to show the current vi mode (if this is set to true and vi-mode is not already enabled then Trueline will enabled it; vi-mode must be otherwise enabled separately in your .bashrc via set -o vi). When set to true a new segment is shown first (i.e before any other segment defined in TRUELINE_SEGMENTS) and it's appearance can be controlled by means of the following variables:
    • TRUELINE_VIMODE_INS_COLORS_STYLE=('black' 'light_blue' 'bold'): insert mode segment foreground/background colors and font style.
    • TRUELINE_VIMODE_CMD_COLORS_STYLE=('black' 'green' 'bold'): command mode segment foreground/background colors and font style.
    • TRUELINE_VIMODE_INS_CURSOR='vert': insert mode cursor shape (possible values are vert, block and under).
    • TRUELINE_VIMODE_CMD_CURSOR='block': command mode cursor shape (possible values are vert, block and under).

Extensions

New segments can be easily added to the prompt by following this template:

_trueline_new_segment_name_segment() {
    local some_content=$(...)
    if [[ -n "$some_content" ]]; then
        local fg_color="$1"
        local bg_color="$2"
        local font_style="$3"
        local segment="$(_trueline_separator)"
        segment+="$(_trueline_content "$fg_color" "$bg_color" "$font_style" " $some_content ")"
        PS1+="$segment"
        _last_color=$bg_color
    fi
}

and then simply including the new_segment_name in your TRUELINE_SEGMENTS array.

PRs with complicated segments are welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].