Code Monkey home page Code Monkey logo

bash-ps1-themes's Introduction

Bash Prompt Themes ๐ŸŒˆ

Bash prompt themes, with a color gradient feature.

How to use

Themes are a combination of a template and a color palette. The template is the prompt itself and the colors from the palette are applied onto it.

Theme names are a combinasion of their template and palette: template_palette like teal_horizon.

Demo the themes

Demo all the themes using:

./demo_themes

Use a theme

To use a theme simply source it to your current shell:

source ./themes/teal_horizon

Persistent use

Clone the repo on your machine because themes aren't fully standalone, they use the lib/lib file from this repo.

Source the theme in your .bashrc. For instance, at the end of your .bashrc, add:

# Change the path with where you put bash-ps1-themes
source ~/bash-ps1-themes/themes/teal_cyber_3

How it works

The themes work with the PROMPT_COMMAND and PS1 environment variable.

The PROMPT_COMMAND invokes a function that in turn invokes other functions to build a PS1 variable.

Development

You can create your own templates and color palettes.

Palette development

Creating a palette

Create a new file in the palettes/ folder and update the following variables to your liking:

#!/bin/bash
palette_primary="#1bcfc6"
palette_primary_dark="#02a199"
palette_secondary="#008cff"
palette_secondary_dark="#0066ba"
palette_accent="#b88914"
palette_accent_dark="#9c7f0c"
palette_gradient_start="#0bb092"
palette_gradient_end="#008cff"
palette_variant_1="#00d7af"
palette_variant_2="#00d7d7"
palette_variant_3="#00d7ff"
palette_text="#d2d2d2"

Viewing a palette

To preview the palette in the terminal, use:

./demo_palettes

./demo_palettes --detailed

Template development

Creating a template

Create a new file in the templates/ folder.

This snippet is an example of a basic template:

#!/bin/bash
scriptDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")
source $scriptDir'/../lib/lib'

prompt_cmd() {
  LINE_1="$(rgb_fg_ps1 $palette_primary)$(current_user) $(rgb_fg_ps1 $palette_secondary)$(basename $PWD)"
  LINE_2="$(rgb_fg_ps1 $palette_accent)$ $(rgb_fg_ps1 $palette_text)"

  PS1="\r\n${LINE_1}\r\n${LINE_2}"
}

export PROMPT_COMMAND='prompt_cmd'

Lib API

Here are some functions you can use in your templates:

# Set the foreground color, all text set after calling this function will be the desired color
rgb_fg_ps1 "#ffffff" 

# Set the background color, all text set after calling this function will be the desired color
rgb_bg_ps1 "#ffffff" 

# Create a foreground gradient over a defined string
fg_gradient_ps1 "#ff0000" "#00ff00" "some string to receive gradient"

# Create a background gradient over a defined string
bg_gradient_ps1 "#ff0000" "#00ff00" "some string to receive gradient"

# Current git branch
gitbranch

See the lib/ source for more functions.

Generating the themes from your new palette/template

Then, to apply the palette to the templates, there is a generate_themes script that combines all sets of templates and palettes together:

./generate_themes

Your theme will be generated in the themes/ folder.

Notice

Works only in Bash shells.

bash-ps1-themes's People

Contributors

gcholette avatar pimsdsigd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.