Highly configurable prompt builder for Bash and ZSH written in Go. It's inspired by the Oh My ZSH Bullet Train theme.
Works well on Linux (Terminator, Konsole, Gnome Terminal) and Mac (Terminal, iTerm). It has no other dependencies than Go and its standard libraries.
On Arch Linux:
yaourt -S gbtOn CentOS/RHEL:
cat > /etc/yum.repos.d/gbt.repo <<END
[gbt]
name=GBT YUM repo
baseurl=https://packagecloud.io/jtyr/gbt/el/7/\$basearch
gpgkey=https://packagecloud.io/jtyr/gbt/gpgkey/jtyr-gbt-4C6E79EFF45439B6.pub.gpg
gpgcheck=1
END
yum install gbtOn Ubuntu/Debian:
curl -L https://packagecloud.io/jtyr/gbt/gpgkey | apt-key add -
echo 'deb https://packagecloud.io/jtyr/gbt/ubuntu/ xenial main' > /etc/apt/sources.list.d/gbt.list
apt-get update
apt-get install gbtOn Mac via Homebrew:
brew tap jtyr/repo
brew install gbtFrom source code:
go get -u github.com/jtyr/gbt
go build -o ~/gbt github.com/jtyr/gbtGBT can be activated by calling it from the shell prompt variable:
# For Bash
PS1='$(gbt $?)'
# For ZSH
PROMPT='$(gbt $?)'In order to display all colors correctly, the terminal should use 256 color scheme:
export TERM="xterm-256color"In order to display all characters of the prompt correctly, the shell should support UTF-8 and Nerd (or at least Powerline) fonts should be installed and set in the terminal application.
### Test the Status car
false
true
### Test the Dir car
cd /
cd /usr/share/doc/sudo
# Display only last 3 elements of the path
export GBT_CAR_DIR_DEPTH="3"
# Display full path
export GBT_CAR_DIR_DEPTH="9999"
# Show only last element of the path
unset GBT_CAR_DIR_DEPTH
cd ~
### Test Time car
# Add the Time car into the train
export GBT_CARS="Status, Os, Time, Hostname, Dir, Sign"
# Set 12h format
export GBT_CAR_TIME_TIME_FORMAT="03:04:05 PM"
# Change background color of the all car
export GBT_CAR_TIME_BG="yellow"
# Change color of Date part
export GBT_CAR_TIME_DATE_FG="black"
# Reset the color of the Date part
unset GBT_CAR_TIME_DATE_FG
# Reset the background color of all Time car
unset GBT_CAR_TIME_BG
# Remove the Date part from the car
export GBT_CAR_TIME_FORMAT=" {{ Time }} "
# Reset the format of the car
unset GBT_CAR_TIME_FORMAT
# Reset the original train
unset GBT_CARS
### Themes
# Load theme
source /usr/share/gbt/themes/square_brackets_multilineThe prompt (train) is assembled from several elements (cars). The look and behavior of whole train as well as each car can be influenced by a set of environment variables. Majority of the
The value of all _BG and _FG variables defines the background and
foreground color of the particular element. The value of the color can be
specified in 3 ways:
Only a limited number of named colors is supported:
blackredgreenyellowbluemagentacyanlight_graydark_graylight_redlight_greenlight_yellowlight_bluelight_magentalight_cyanwhitedefault(default color of the terminal)
Examples:
# Set the background color of the `Dir` car to red
export GBT_CAR_DIR_BG="red"
# Set the foreground color of the `Dir` car to white
export GBT_CAR_DIR_FG="white"Color can also by expressed by a single number in the range from 0 to
255. The color of each number in that range is visible in the 256-color
lookup table on
Wikipedia. The named
colors described above are the first 16 numbers from the lookup table.
Examples:
# Set the background color of the `Dir` car to red
export GBT_CAR_DIR_BG="1"
# Set the foreground color of the `Dir` car to white
export GBT_CAR_DIR_FG="15"Arbitrary color can be expressed in the form of RGB triplet.
Examples:
# Set the background color of the `Dir` car to red
export GBT_CAR_DIR_BG="170;0;0"
# Set the foreground color of the `Dir` car to white
export GBT_CAR_DIR_FG="255;255;255"Formatting is done via _FM variables. The possible values are:
-
boldMakes the text bold. Not all font characters have variant for bold formatting.
-
underlineMakes the text underlined.
-
blinkMakes the text to blink.
-
noneNo formatting applied.
Example:
# Set the directory name to be bold export GBT_CAR_DIR_FM="bold"
-
GBT_CARS="Status, Os, Hostname, Dir, Git, Sign"List of cars used in the train.
To add a new car into the train, the whole variable must be redefined. For example in order to add the
Timecar into the default set of cars between theOsandHostnamecar, the variable should look like this:export GBT_CARS="Status, Os, Time, Hostname, Dir, Git, Sign"
-
GBT_RCARS="Time"The same like
GBT_CARSbut for the right hand side prompt.# Add the Custom car into the right hand site car to have the separator visible export GBT_RCARS="Custom, Time" # Make the Custom car to be invisible (zero length text) export GBT_CAR_CUSTOM_BG="default" export GBT_CAR_CUSTOM_FORMAT="" # Show only time export GBT_CAR_TIME_FORMAT=" {{ Time }} " # Set the right hand side prompt (ZSH only) export RPROMPT='$(gbt -right)'
-
GBT_SEPARATOR=""Character used to separate cars in the train.
-
GBT_RSEPARATOR=""The same like
GBT_SEPARATORbut for the right hand side prompt. -
GBT_CAR_BGBackground color inherited by the top background color variable of every car. That allows to set the background color of all cars via single variable.
-
GBT_CAR_FGForeground color inherited by the top foreground color variable of every car. That allows to set the foreground color of all cars via single variable.
-
GBT_CAR_FMFormatting inherited by the top formatting variable of every car. That allows to set the formatting of all cars via single variable.
-
GBT_BEGINNING_BG="default"Background color of the text shown at the beginning of the train.
-
GBT_BEGINNING_FG="default"Foreground color of the text shown at the beginning of the train.
-
GBT_BEGINNING_FM="none"Formatting of the text shown at the beginning of the train.
-
GBT_BEGINNING_TEXT=""Text shown at the beginning of the train.
-
GBT_SHELLIndicates which shell is used. The value can be either
zshorbash. By default, the value is extracted from the$SHELLenvironment variable. Set this variable tobashif your default shell is ZSH but you want to test GBT in Bash:export GBT_SHELL="bash" bash
-
GBT_DEBUG="0"Shows more verbose output if some of the car modules cannot be imported.
The main purpose of this car is to provide the possibility to create car with custom text.
-
GBT_CAR_CUSTOM_BG="yellow"Background color of the car.
-
GBT_CAR_CUSTOM_FG="default"Foreground color of the car.
-
GBT_CAR_CUSTOM_FM="none"Formatting of the car.
-
GBT_CAR_CUSTOM_FORMAT=" {{ Text }} "Format of the car.
-
GBT_CAR_CUSTOM_TEXT_BGBackground color of the
{{ Text }}element. -
GBT_CAR_CUSTOM_TEXT_FGForeground color of the
{{ Text }}element. -
GBT_CAR_CUSTOM_TEXT_FMFormatting of the
{{ Text }}element. -
GBT_CAR_CUSTOM_TEXT_TEXT="?"Text content of the
{{ Text }}element. -
GBT_CAR_CUSTOM_TEXT_CMDThe
{{ Text }}element will be replaced by standard output of the command specified in this variable. Content of theGBT_CAR_CUSTOM_TEXT_TEXTvariable takes precedence over this variable.# Show 1 minute loadavg as the content of the Text element export GBT_CAR_CUSTOM_CMD="uptime | sed --e 's/.*load average: //' -e 's/,.*//'"
-
GBT_CAR_CUSTOM_DISPLAY="1"Whether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_CUSTOM_DISPLAY_CMDCommand which gets executed in order to evaluate whether the car should be displayed or not. Content of the
GBT_CAR_CUSTOM_DISPLAYvariable takes precedence over this variable.# Show percentage of used disk space of the root partition export GBT_CAR_CUSTOM_TEXT_CMD="df -h --output=pcent / | tail -n1 | sed -re 's/\s//g' -e 's/%/%%/'" # Display the car only if the percentage is above 90% export GBT_CAR_CUSTOM_DISPLAY_CMD="[[ $(df -h --output=pcent / | tail -n1 | sed -re 's/\s//g' -e 's/%//') -gt 70 ]] && echo YES"
-
GBT_CAR_CUSTOM_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_CUSTOM_SEPCustom separator string for this car.
Multiple Custom cars can be used in the GBT_CARS variable. Just add some
identifier behind the car name. To set properties of the new car, just add the
same identifier into the environment variable:
# Adding Custom and Custo1 car
export GBT_CARS="Status, Os, Custom, Custom1, Hostname, Dir, Git, Sign"
# The text of the default Custom car
export GBT_CAR_CUSTOM_TEXT_TEXT="default"
# The text of the Custom1 car
export GBT_CAR_CUSTOM1_TEXT_TEXT="1"
# Set different background color for the Custom1 car
export GBT_CAR_CUSTOM1_BG="magenta"Car that displays current directory name.
-
GBT_CAR_DIR_BG="blue"Background color of the car.
-
GBT_CAR_DIR_FG="light_gray"Foreground color of the car.
-
GBT_CAR_DIR_FM="none"Formatting of the car.
-
GBT_CAR_DIR_FORMAT=" {{ Dir }} "Format of the car.
-
GBT_CAR_DIR_DIR_BGBackground color of the
{{ Dir }}element. -
GBT_CAR_DIR_DIR_FGForeground color of the
{{ Dir }}element. -
GBT_CAR_DIR_DIR_FMFormatting of the
{{ Dir }}element. -
GBT_CAR_DIR_DIR_TEXTText content of the
{{ Dir }}element. The directory name. -
GBT_CAR_DIR_DIRSEPOS-default character used to separate directories.
-
GBT_CAR_DIR_HOMESIGN="~"Character which represents the user's home directory. If set to empty string, full home directory path is used instead.
-
GBT_CAR_DIR_DEPTH="1"Number of directories to show.
-
GBT_CAR_DIR_DISPLAY="1"Whether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_DIR_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_DIR_SEPCustom separator string for this car.
Car that displays how long each shell command run.
-
GBT_CAR_EXECTIME_BG="light_gray"Background color of the car.
-
GBT_CAR_EXECTIME_FG="black"Foreground color of the car.
-
GBT_CAR_EXECTIME_FM="none"Formatting of the car.
-
GBT_CAR_EXECTIME_FORMAT=" {{ Time }} "Format of the car.
-
GBT_CAR_EXECTIME_TIME_BGBackground color of the
{{ Time }}element. -
GBT_CAR_EXECTIME_TIME_FGForeground color of the
{{ Time }}element. -
GBT_CAR_EXECTIME_TIME_FMFormatting of the
{{ Time }}element. -
GBT_CAR_EXECTIME_TIME_TEXTText content of the
{{ Time }}element. The execution time. -
GBT_CAR_EXECTIME_DIRSEPOS-default character used to separate directories.
-
GBT_CAR_EXECTIME_PRECISION="0"Sub-second precision to show.
-
GBT_CAR_EXECTIME_SECSThe number of seconds the command run in shell. This variable is defined in the source file as shown bellow.
-
GBT_CAR_EXECTIME_BELL="0"Sound console bell if the executed command exceeds specified number of seconds. Value set to
0disables the bell (default). -
GBT_CAR_EXECTIME_DISPLAY="1"Whether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_EXECTIME_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_EXECTIME_SEPCustom separator string for this car.
In order to allow this car to calculate the execution time, the following must be loaded in the shell:
# For Bash
source /usr/share/gbt/sources/exec_time/bash
# For ZSH
source /usr/share/gbt/sources/exec_time/zshCar that displays information about a local Git repository. This car is displayed only if the current directory is a Git repository.
-
GBT_CAR_GIT_BG="light_gray"Background color of the car.
-
GBT_CAR_GIT_FG="black"Foreground color of the car.
-
GBT_CAR_GIT_FM="none"Formatting of the car.
-
GBT_CAR_GIT_FORMAT=" {{ Icon }} {{ Head }} {{ Status }}{{ Ahead }}{{ Behind }} "Format of the car.
-
GBT_CAR_GIT_ICON_BGBackground color of the
{{ Icon }}element. -
GBT_CAR_GIT_ICON_FGForeground color of the
{{ Icon }}element. -
GBT_CAR_GIT_ICON_FMFormatting of the
{{ Icon }}element. -
GBT_CAR_GIT_ICON_TEXT=""Text content of the
{{ Icon }}element. -
GBT_CAR_GIT_HEAD_BGBackground color of the
{{ Head }}element. -
GBT_CAR_GIT_HEAD_FGForeground color of the
{{ Head }}element. -
GBT_CAR_GIT_HEAD_FMFormatting of the
{{ Head }}element. -
GBT_CAR_GIT_HEAD_TEXTText content of the
{{ Head }}element. The branch or tag name or the commit ID. -
GBT_CAR_GIT_STATUS_BGBackground color of the
{{ Status }}element. -
GBT_CAR_GIT_STATUS_FGForeground color of the
{{ Status }}element. -
GBT_CAR_GIT_STATUS_FMFormatting of the
{{ Status }}element. -
GBT_CAR_GIT_STATUS_FORMATFormat of the
{{ Status }}element. The content is either{{ Dirty }}or{{ Clean }}depending on the state of the local Git repository. -
GBT_CAR_GIT_DIRTY_BGBackground color of the
{{ Dirty }}element. -
GBT_CAR_GIT_DIRTY_FG="red"Foreground color of the
{{ Dirty }}element. -
GBT_CAR_GIT_DIRTY_FMFormatting of the
{{ Dirty }}element. -
GBT_CAR_GIT_DIRTY_TEXT="✘"Text content of the
{{ Dirty }}element. -
GBT_CAR_GIT_CLEAN_BGBackground color of the
{{ Clean }}element. -
GBT_CAR_GIT_CLEAN_FG="green"Foreground color of the
{{ Clean }}element. -
GBT_CAR_GIT_CLEAN_FMFormatting of the
{{ Clean }}element. -
GBT_CAR_GIT_CLEAN_TEXT="✔"Text content of the
{{ Clean }}element. -
GBT_CAR_GIT_AHEAD_BGBackground color of the
{{ Ahead }}element. -
GBT_CAR_GIT_AHEAD_FGForeground color of the
{{ Ahead }}element. -
GBT_CAR_GIT_AHEAD_FMFormatting of the
{{ Ahead }}element. -
GBT_CAR_GIT_AHEAD_TEXT=" ⬆"Text content of the
{{ Ahead }}element. -
GBT_CAR_GIT_BEHIND_BGBackground color of the
{{ Behind }}element. -
GBT_CAR_GIT_BEHIND_FGForeground color of the
{{ Behind }}element. -
GBT_CAR_GIT_BEHIND_FMFormatting of the
{{ Behind }}element. -
GBT_CAR_GIT_BEHIND_TEXT=" ⬇"Text content of the
{{ Behind }}element. -
GBT_CAR_GIT_DISPLAYWhether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_GIT_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_GIT_SEPCustom separator string for this car.
Car that displays username of the currently logged user and the hostname of the local machine.
-
GBT_CAR_HOSTNAME_BG="dark_gray"Background color of the car.
-
GBT_CAR_HOSTNAME_FG="252"Foreground color of the car.
-
GBT_CAR_HOSTNAME_FM="none"Formatting of the car.
-
GBT_CAR_HOSTNAME_FORMAT=" {{ UserHost }} "Format of the car.
-
GBT_CAR_HOSTNAME_USERHOST_BGBackground color of the
{{ UserHost }}element. -
GBT_CAR_HOSTNAME_USERHOST_FGForeground color of the
{{ UserHost }}element. -
GBT_CAR_HOSTNAME_USERHOST_FMFormatting of the
{{ UserHost }}element. -
GBT_CAR_HOSTNAME_USERHOST_FORMATFormat of the
{{ UserHost }}element. The value is either{{ Admin }}@{{ Host }}if the user isrootor{{ User }}@{{ Host }}if the user is a normal user. -
GBT_CAR_HOSTNAME_ADMIN_BGBackground color of the
{{ Admin }}element. -
GBT_CAR_HOSTNAME_ADMIN_FGForeground color of the
{{ Admin }}element. -
GBT_CAR_HOSTNAME_ADMIN_FMFormatting of the
{{ Admin }}element. -
GBT_CAR_HOSTNAME_ADMIN_TEXTText content of the
{{ Admin }}element. The user name. -
GBT_CAR_HOSTNAME_USER_BGBackground color of the
{{ User }}element. -
GBT_CAR_HOSTNAME_USER_FGForeground color of the
{{ User }}element. -
GBT_CAR_HOSTNAME_USER_FMFormatting of the
{{ User }}element. -
GBT_CAR_HOSTNAME_USER_TEXTText content of the
{{ User }}element. The user name. -
GBT_CAR_HOSTNAME_HOST_BGBackground color of the
{{ Host }}element. -
GBT_CAR_HOSTNAME_HOST_FGForeground color of the
{{ Host }}element. -
GBT_CAR_HOSTNAME_HOST_FMFormatting of the
{{ Host }}element. -
GBT_CAR_HOSTNAME_HOST_TEXTText content of the
{{ Host }}element. The host name. -
GBT_CAR_HOSTNAME_DISPLAY="1"Whether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_HOSTNAME_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_HOSTNAME_SEPCustom separator string for this car.
Car that displays icon of the operating system.
-
GBT_CAR_OS_BG="235"Background color of the car.
-
GBT_CAR_OS_FG="white"Foreground color of the car.
-
GBT_CAR_OS_FM="none"Formatting of the car.
-
GBT_CAR_OS_FORMAT=" {{ Symbol }} "Format of the car.
-
GBT_CAR_OS_SYMBOL_BGBackground color of the
{{ Symbol }}element. -
GBT_CAR_OS_SYMBOL_FGForeground color of the
{{ Symbol }}element. -
GBT_CAR_OS_SYMBOL_FMFormatting of the
{{ Symbol }}element. -
GBT_CAR_OS_SYMBOL_TEXTText content of the
{{ Symbol }}element. -
GBT_CAR_OS_NAMEThe name of the symbol to display. Default value is selected by the system the shell runs at. Possible names and their symbols are:
amznandroidarcharcharmcentoscloudcoreosdarwindebiandockerelementaryfedorafreebsdgentoolinuxlinuxmintmageiamandrivaopensuseraspbianredhatsabayonslackwareubuntuwindows
Example:
export GBT_CAR_OS_NAME="arch"
-
GBT_CAR_OS_DISPLAY="1"Whether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_OS_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_OS_SEPCustom separator string for this car.
Car that displays Python Virtual Environment name. This car is displayed only if the Python Virtual Environment is activated. The activation script usually prepends the shell prompt by the Virtual Environment name by default. In order to disable it, the following environment variable must be set:
export VIRTUAL_ENV_DISABLE_PROMPT="1"Variables used by the car:
-
GBT_CAR_PYVIRTENV_BG="222"Background color of the car.
-
GBT_CAR_PYVIRTENV_FG="black"Foreground color of the car.
-
GBT_CAR_PYVIRTENV_FM="none"Formatting of the car.
-
GBT_CAR_PYVIRTENV_FORMAT=" {{ Icon }} {{ Name }} "Format of the car.
-
GBT_CAR_PYVIRTENV_ICON_BGBackground color of the
{{ Icon }}element. -
GBT_CAR_PYVIRTENV_ICON_FGForeground color of the
{{ Icon }}element. -
GBT_CAR_PYVIRTENV_ICON_FMFormatting of the
{{ Icon }}element. -
GBT_CAR_PYVIRTENV_ICON_TEXTText content of the
{{ Icon }}element. -
GBT_CAR_PYVIRTENV_NAME_BGBackground color of the
{{ Name }}element. -
GBT_CAR_PYVIRTENV_NAME_FG="33"Foreground color of the
{{ NAME }}element. -
GBT_CAR_PYVIRTENV_NAME_FMFormatting of the
{{ Name }}element. -
GBT_CAR_PYVIRTENV_NAME_TEXTThe name of the Python Virtual Environment deducted from the
VIRTUAL_ENVenvironment variable. -
GBT_CAR_PYVIRTENV_DISPLAYWhether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_PYVIRTENV_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_PYVIRTENV_SEPCustom separator string for this car.
Car that displays prompt character for the admin and user at the end of the train.
-
GBT_CAR_SIGN_BG="default"Background color of the car.
-
GBT_CAR_SIGN_FG="default"Foreground color of the car.
-
GBT_CAR_SIGN_FM="none"Formatting of the car.
-
GBT_CAR_SIGN_FORMAT=" {{ Symbol }} "Format of the car.
-
GBT_CAR_SIGN_SYMBOL_BGBackground color of the
{{ Symbol }}element. -
GBT_CAR_SIGN_SYMBOL_FGForeground color of the
{{ Symbol }}element. -
GBT_CAR_SIGN_SYMBOL_FM="bold"Formatting of the
{{ Symbol }}element. -
GBT_CAR_SIGN_SYMBOL_FORMATFormat of the
{{ Symbol }}element. The format is either{{ Admin }}if the UID is 0 or{{ User }}if the UID is not 0. -
GBT_CAR_SIGN_ADMIN_BGBackground color of the
{{ Admin }}element. -
GBT_CAR_SIGN_ADMIN_FG="red"Foreground color of the
{{ Admin }}element. -
GBT_CAR_SIGN_ADMIN_FMFormatting of the
{{ Admin }}element. -
GBT_CAR_SIGN_ADMIN_TEXT="#"Text content of the
{{ Admin }}element. -
GBT_CAR_SIGN_USER_BGBackground color of the
{{ User }}element. -
GBT_CAR_SIGN_USER_FG="light_green"Foreground color of the
{{ User }}element. -
GBT_CAR_SIGN_USER_FMFormatting of the
{{ User }}element. -
GBT_CAR_SIGN_USER_TEXT="$"Text content of the
{{ User }}element. The user name. -
GBT_CAR_SIGN_DISPLAY="1"Whether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_SIGN_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_SIGN_SEPCustom separator string for this car.
Car that visualizes return code of every command. By default, this car is displayed only when the return code is non-zero. If you want to display it even if the return code is zero, set the following variable:
export GBT_CAR_STATUS_DISPLAY="1"Variables used by the car:
-
GBT_CAR_STATUS_BGBackground color of the car. It's either
GBT_CAR_STATUS_OK_BGif the last command returned0return code otherwise theGBT_CAR_STATUS_ERROR_BGis used. -
GBT_CAR_STATUS_FG="default"Foreground color of the car. It's either
GBT_CAR_STATUS_OK_FGif the last command returned0return code otherwise theGBT_CAR_STATUS_ERROR_FGis used. -
GBT_CAR_STATUS_FM="none"Formatting of the car. It's either
GBT_CAR_STATUS_OK_FMif the last command returned0return code otherwise theGBT_CAR_STATUS_ERROR_FMis used. -
GBT_CAR_STATUS_FORMAT=" {{ Symbol }} "Format of the car. This can be changed to contain also the value of the return code:
export GBT_CAR_STATUS_FORMAT=" {{ Symbol }} {{ Code }} "
-
GBT_CAR_STATUS_SYMBOL_BGBackground color of the
{{ Symbol }}element. -
GBT_CAR_STATUS_SYMBOL_FGForeground color of the
{{ Symbol }}element. -
GBT_CAR_STATUS_SYMBOL_FM="bold"Formatting of the
{{ Symbol }}element. -
GBT_CAR_STATUS_SYMBOL_FORMATFormat of the
{{ Symbol }}element. The format is either{{ Error }}if the last command returned non zero return code otherwise{{ User }}is used. -
GBT_CAR_STATUS_CODE_BG="red"Background color of the
{{ Code }}element. -
GBT_CAR_STATUS_CODE_FG="light_gray"Foreground color of the
{{ Code }}element. -
GBT_CAR_STATUS_CODE_FM="none"Formatting of the
{{ Code }}element. -
GBT_CAR_STATUS_CODE_TEXTText content of the
{{ Code }}element. The return code. -
GBT_CAR_STATUS_ERROR_BG="red"Background color of the
{{ Error }}element. -
GBT_CAR_STATUS_ERROR_FG="light_gray"Foreground color of the
{{ Error }}element. -
GBT_CAR_STATUS_ERROR_FM="none"Formatting of the
{{ Error }}element. -
GBT_CAR_STATUS_ERROR_TEXT="✘"Text content of the
{{ Error }}element. -
GBT_CAR_STATUS_OK_BG="green"Background color of the
{{ Ok }}element. -
GBT_CAR_STATUS_OK_FG="light_gray"Foreground color of the
{{ Ok }}element. -
GBT_CAR_STATUS_OK_FM="none"Formatting of the
{{ Ok }}element. -
GBT_CAR_STATUS_OK_TEXT="✔"Text content of the
{{ Ok }}element. -
GBT_CAR_STATUS_DISPLAYWhether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_STATUS_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_STATUS_SEPCustom separator string for this car.
Car that displays current date and time.
-
GBT_CAR_TIME_BG="light_blue"Background color of the car.
-
GBT_CAR_TIME_FG="light_gray"Foreground color of the car.
-
GBT_CAR_TIME_FM="none"Formatting of the car.
-
GBT_CAR_TIME_FORMAT=" {{ DateTime }} "Format of the car.
-
GBT_CAR_TIME_DATETIME_BGBackground color of the
{{ DateTime }}element. -
GBT_CAR_TIME_DATETIME_FGForeground color of the
{{ DateTime }}element. -
GBT_CAR_TIME_DATETIME_FMFormatting of the
{{ DateTime }}element. -
GBT_CAR_TIME_DATETIME_FORMAT="{{ Date }} {{ Time }}"Format of the
{{ DateTime }}element. -
GBT_CAR_TIME_DATE_BGBackground color of the
{{ Date }}element. -
GBT_CAR_TIME_DATE_FGForeground color of the
{{ Date }}element. -
GBT_CAR_TIME_DATE_FMFormatting of the
{{ Date }}element. -
GBT_CAR_TIME_DATE_FORMAT="Mon 02 Jan"Format of the
{{ Date }}element. The format is using placeholders as described in thetime.Format()Go function. For exampleJanuaryis a placeholder for current full month name andPMis a placeholderAMif the current time is before noon orPMif the current time is after noon. So in order to display date in the format ofYYYY-MM-DD, the value of this variable should be2006-01-02. -
GBT_CAR_TIME_TIME_BGBackground color of the
{{ Host }}element. -
GBT_CAR_TIME_TIME_FG="light_yellow"Foreground color of the
{{ Host }}element. -
GBT_CAR_TIME_TIME_FMFormatting of the
{{ Host }}element. -
GBT_CAR_TIME_TIME_FORMAT="15:04:05"Text content of the
{{ Host }}element. The format principles are the same like in the case of theGBT_CAR_TIME_DATE_FORMATvariable above. So in order to display time in the 12h format, the value of this variable should be03:04:05 PM. -
GBT_CAR_TIME_DISPLAY="1"Whether to display this car if it's in the list of cars (
GBT_CARS). -
GBT_CAR_TIME_WRAP="0"Whether to wrap the prompt line in front of this car.
-
GBT_CAR_TIME_SEPCustom separator string for this car.
It's possible to use GBT to generate prompt string and forward it to remote
server via SSH so we can have GBT-like prompt also in the remote shell. The
main limitation is that the text of the cars can only be dynamic if only prompt
escape sequences
recognized by the remote shell are used. As most of the remote servers have
Bash as their default shell, we need to create Bash-compatible PS1 string.
The principle is that we need to create a file which we will use to configure
the output of locally executed GBT as the PS1 for the remote server. This
configuration also re-definition the TEXT fields form certain cars to use
Bash escape sequences instead (e.g. \u for the user name). We write this
configuration into the ~/.gbt.theme file like this:
cat <<END > ~/.gbt.theme
export GBT_CARS='Os, Time, Hostname, Dir, Sign'
export GBT_CAR_OS_NAME='cloud'
export GBT_CAR_TIME_FORMAT=' \t '
export GBT_CAR_HOSTNAME_USER_TEXT='\u'
export GBT_CAR_HOSTNAME_HOST_TEXT='\h'
export GBT_CAR_DIR_DIR_TEXT='\W'
export GBT_CAR_SIGN_SYMBOL_FORMAT='\\\$'
export GBT_SHELL='_bash'
ENDThen we can tell SSH to execute remote command which consists of locally generated GBT output, which is written into a file on the remote server, and the Bash command which loads that generated file as its RC file:
ssh myserver -t "echo \"PS1='$(source ~/.gbt.theme; gbt)'\" > /tmp/.gbt; bash --rcfile /tmp/.gbt"Similar principle is used to get the PS1 through the run of su command.
We just need to run Bash command which loads the generated file as its RC file:
su -c 'bash --rcfile /tmp/.gbt' - myuserThe same principle can be used for sudo command:
sudo su -c 'bash --rcfile /tmp/.gbt' - myuserTo get GBT-like prompt inside a Docker container, we need to copy the generated
file into the container and then execute Bash like in the case of su or
sudo:
docker cp /tmp/.gbt pensive_pasteur:/tmp
docker exec -it pensive_pasteur /bin/bash --rcfile /tmp/.gbtTo get GBT-like prompt inside a Vagrant when running vagrant ssh, we can use
the same approach like for SSH above:
vagrant ssh --command "echo \"PS1='$(source ~/.gbt.theme; gbt)'\" > /tmp/.gbt; bash --rcfile /tmp/.gbt"More complete and seamless implementation of the above, including the passing
of the PS1 string via docker, ssh, su, sudo and vagrant commands,
is available as a part of this repo. You can start using it by doing the
following:
export GBT__HOME="/usr/share/gbt"
source "$GBT__HOME/sources/prompt_forwarding/local"
alias docker="gbt_docker"
alias ssh="gbt_ssh"
alias su="gbt_su"
alias sudo="gbt_sudo"
alias vagrant="gbt_vagrant"If you want to have the alias available only on the remote machine, prepend the
alias by gbt___. For example to have the sudo alias, using the gbt_sudo
function, available only on the remote machine, define the alias like this:
alias gbt__sudo="gbt_sudo"Then just SSH to some remote server or enter some Docker container or Vagrant box and you should get GBT-like looking prompt:
Jiri Tyr
MIT