Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gcholette authored Oct 10, 2023
2 parents cbd5ed4 + 61b35a3 commit 5e6f8ec
Show file tree
Hide file tree
Showing 88 changed files with 1,071 additions and 159 deletions.
148 changes: 127 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,149 @@
<h1 align="center">
Bash PS1 Themes :rainbow:
Bash Prompt Themes :rainbow:
</h1>

<p align="center">
Themes for the PS1 bash environment variable, with a color gradient feature.
Bash prompt themes, with a color gradient feature.
</p>
<p align="center">
<img src="./photos/magenta_gradient3.png"/>
<img src="misc/photos/demo_3.png"/>
<img src="misc/photos/teal_horizon_demo.png"/>
<img src="misc/photos/demo_4.png"/>
</p>

## How to use

For persistent use, copy the theme's source in your `.bashrc`.

The theme files have `export PS1=...` at the end, so they only need to be executed to apply the theme to the current shell.

See themes in `./themes/`, try them out by using `source ./themes/Dark-red/dark_red_1`

Works only in Bash shells, incompatible with zsh.
# How to use

### Examples
Find more examples in the `themes/` folders.
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.

![original_grad](./photos/original_gradient.png)
Theme names are a combinasion of their template and palette: `template_palette` like `teal_horizon`.

![teal_theme](./photos/teal_theme1.png)
## Demo the themes

![magenta_grad](./photos/magenta_gradient3.png)
Demo all the themes using:

![red_theme](https://user-images.githubusercontent.com/8711020/142965044-cfb09fba-b78a-4acd-9e0c-91fab0c0126c.png)
```bash
./demo_themes
```
<img src="misc/photos/demo_themes.png"/>

![teal_light_theme](https://user-images.githubusercontent.com/8711020/142966562-12f60fbc-15f8-4e5f-a78e-5b6c177cac06.png)
## Use a theme

![image](https://user-images.githubusercontent.com/8711020/142968847-53f5aaf3-0ae2-49db-ac39-90a41b331f04.png)
To use a theme simply source it to your current shell:

## How it works
```bash
source ./themes/teal_horizon
```

To generate gradients with [Bash colors](https://misc.flogisoft.com/bash/tip_colors_and_formatting#colors1), the [grad()](./util/grad) function spreads x consecutive color ids across a word, starting at a certain color id.
## Persistent use
Clone the repo on your machine because themes aren't fully standalone, they use the `lib/lib` file from this repo.

Usage: `$(grad 83 6 "localhost")`
Source the theme in your `.bashrc`. For instance, at the end of your `.bashrc`, add:
```bash
# Change the path with where you put bash-ps1-themes
source ~/bash-ps1-themes/themes/teal_cyber_3
```
# How it works

![image](https://user-images.githubusercontent.com/8711020/142923686-7d3c7072-3afe-46c1-a846-f7229b726c6f.png)
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:

```bash
#!/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:

```bash
./demo_palettes
```
<img src="misc/photos/demo_palettes.png"/>

```bash
./demo_palettes --detailed
```
<img src="misc/photos/demo_palettes_detailed.png"/>

## Template development

### Creating a template

Create a new file in the `templates/` folder.

This snippet is an example of a basic template:

```bash
#!/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:
```bash
# 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:
```bash
./generate_themes
```

Your theme will be generated in the `themes/` folder.

# Notice
Works only in Bash shells.
89 changes: 89 additions & 0 deletions demo_palettes
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash
scriptDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")
themesDir="${scriptDir}/themes"
palettesDir="${scriptDir}/palettes"
source $scriptDir'/lib/lib'

detailed=0
for arg in "$@"; do
if [ "$arg" = "--detailed" ]; then
detailed=1
break
fi
done

clear
printf "\033[48;5;4m"
center_string Palettes
no_color

if [ $detailed -eq 1 ]; then

for FILE in $(ls $palettesDir);
do
if [ $FILE != 'README.md' ]
then
printf "\033[3m"
printf "\033[48;5;17m"
center_string $FILE
no_color
echo
source $palettesDir/$FILE

printf "\033[1mMain colors$(no_color)\n\n"
printf "Primary "
printf "$(rgb_bg $palette_primary) $(no_color) "
printf "$(rgb_bg $palette_primary_dark) $(no_color) \n\n"
printf "Secondary "
printf "$(rgb_bg $palette_secondary) $(no_color) "
printf "$(rgb_bg $palette_secondary_dark) $(no_color) \n\n"
printf "Accent "
printf "$(rgb_bg $palette_accent) $(no_color) "
printf "$(rgb_bg $palette_accent_dark) $(no_color) \n\n"

printf "\033[1mGradient$(no_color)\n\n"

printf "$(bg_gradient $palette_gradient_start $palette_gradient_end ' ') $(no_color)"
printf "$(bg_gradient $palette_gradient_start $palette_gradient_end ' ') $(no_color)"
printf "$(bg_gradient $palette_gradient_start $palette_gradient_end ' ') $(no_color)"
printf "$(bg_gradient $palette_gradient_start $palette_gradient_end ' ') $(no_color)"
printf "$(bg_gradient $palette_gradient_start $palette_gradient_end ' ') $(no_color) \n\n"
printf "$(bg_gradient $palette_gradient_start $palette_gradient_end ' ') $(no_color)"
printf "$(bg_gradient $palette_gradient_start $palette_gradient_end ' ') $(no_color)\n\n"

printf "\033[1mVariants$(no_color)\n\n"
printf "$(rgb_bg $palette_variant_1) $(no_color) "
printf "$(rgb_bg $palette_variant_2) $(no_color) "
printf "$(rgb_bg $palette_variant_3) $(no_color) - "

printf "$(rgb_bg $palette_variant_1) $(no_color)"
printf "$(rgb_bg $palette_variant_2) $(no_color)"
printf "$(rgb_bg $palette_variant_3) $(no_color)"
printf '\n\n'

printf "\033[1mText color:$(no_color) $(rgb_fg $palette_text)this is the text color$(no_color) "

no_color
echo
echo
fi
done

else

for FILE in $(ls $palettesDir);
do
if [ $FILE != 'README.md' ]
then
printf "\033[3m"
printf "\033[48;5;17m"
no_color
printf "\n"
source $palettesDir/$FILE

printf "%-10s %s\n" $FILE "$(rgb_bg $palette_primary) $(no_color) $(rgb_bg $palette_secondary) $(no_color) $(bg_gradient $palette_gradient_start $palette_gradient_end ' ')"
printf "$(no_color) "
echo
fi
done
fi
33 changes: 33 additions & 0 deletions demo_themes
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
scriptDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")
themesDir="${scriptDir}/themes"
source $scriptDir'/lib/lib'

clear

printf "\033[48;5;4m"
center_string Themes Demo
no_color

for FILE in $(ls $themesDir);
do
if [ $FILE != 'README.md' ] && [ $FILE != 'to_refactor' ] && [ $FILE != 'templates' ] && [ $FILE != 'to_refactor_2' ] && [ $FILE != 'palettes' ]
then
printf "\033[3m"
printf "\033[48;5;17m"
center_string $FILE
no_color
source $themesDir/$FILE
eval $PROMPT_COMMAND
PS1_EVAL=$(eval "echo \"$PS1\"")
PS1_EVAL=$(echo "$PS1_EVAL" | sed 's/\\\[//g;s/\\\]//g')
echo -e "$PS1_EVAL"
no_color
echo
echo
fi
done

printf "\033[48;5;17m"
center_string ''
no_color
41 changes: 41 additions & 0 deletions generate_themes
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
scriptDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")

## this script combines the contents of the palettes and templates folders
## to create individual themes for every variation of every template and palettes.
## It overwrites the files inside themes, but does not touch manually created files
## that do not match the palette_template file name format.


palettes_dir="$scriptDir/palettes"
templates_dir="$scriptDir/templates"
themes_dir="$scriptDir/themes"

if [ ! -d $themes_dir ]; then
mkdir $themes_dir
fi

for palette in "${palettes_dir}"/*; do
for template in "${templates_dir}"/*; do
palette_name="$(basename $palette)"
template_name="$(basename $template)"

theme_file_name="${palette_name%%.*}_${template_name%%.*}"

theme_file="$themes_dir/$theme_file_name"
if [ ! -f $themes_file ]; then
touch "${theme_file}"
chmod +x "${theme_file}"
else
# Clear the file if it exists
printf "" > $theme_file
fi

# Theme script contents
echo '#!/bin/bash' >> $theme_file
echo 'scriptDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")' >> $theme_file
echo "source \$scriptDir'/../lib/lib'" >> $theme_file
echo "source \$scriptDir'/../palettes/${palette_name}'" >> $theme_file
echo "source \$scriptDir'/../templates/${template_name}'" >> $theme_file
done
done
Loading

0 comments on commit 5e6f8ec

Please sign in to comment.