-
Notifications
You must be signed in to change notification settings - Fork 28
Adding More Colors with terminal scripts
Credit @Jiogo18
The Bash script defines a function create_custom_color
that generates a color swatch image and a corresponding SCSS file with a CSS variable for the color.
function create_custom_color () {
color=$1
rgb=$2
mkdir -p static/img/theme-colors assets/css/color
ffmpeg -f lavfi -i color=$rgb:50x50:d=3,format=rgb24 -frames:v 1 static/img/theme-colors/$color.png -y
echo -en ":root {\n --accent: $rgb;\n}" > assets/css/color/$color.scss
}
-
color
: The name of the color (e.g.,yellow
,cyan
). -
rgb
: The RGB hex code of the color (e.g.,#FFCE02
,#00BFBF
).
-
Create Directories
The script ensures that the directoriesstatic/img/theme-colors
andassets/css/color
exist. If they don't, it creates them usingmkdir -p
. -
Generate Color Swatch Image
Usingffmpeg
, the script generates a 50x50 pixel image filled with the specified color. The image is saved as$color.png
instatic/img/theme-colors/
. -
Create SCSS File
It writes a SCSS file defining a CSS variable--accent
with the specified RGB value. This file is saved as$color.scss
inassets/css/color/
.
create_custom_color yellow "#FFCE02"
create_custom_color cyan "#00BFBF"
Run the above commands in your terminal to add the colors "yellow" and "cyan" to your website.
For those using NuShell, the following script achieves the same functionality with a slightly different syntax.
def create_custom_color [color: string, rgb: string] {
mkdir static/img/theme-colors assets/css/color
ffmpeg -f lavfi -i $"color=($rgb):50x50:d=3,format=rgb24" -frames:v 1 $"static/img/theme-colors/($color).png" -y
$":root {(char newline) --accent: ($rgb);(char newline)}" | save $"assets/css/color/($color).scss" --force
}
-
color
: The name of the color. -
rgb
: The RGB hex code of the color.
-
Create Directories
Similar to the Bash script, it creates the necessary directories usingmkdir
. -
Generate Color Swatch Image
Utilizesffmpeg
to generate a 50x50 pixel image filled with the specified color. The image is saved as$color.png
instatic/img/theme-colors/
. -
Create SCSS File
Constructs a string defining the CSS variable--accent
and saves it to$color.scss
inassets/css/color/
using thesave
command with the--force
flag to overwrite if necessary.
create_custom_color yellow "#FFCE02"
create_custom_color cyan "#00BFBF"
Execute these commands in your NuShell environment to add the desired colors.