Skip to content

Commit

Permalink
feat:Support TOML configs
Browse files Browse the repository at this point in the history
  • Loading branch information
egeesin committed Apr 17, 2024
1 parent d1e66a8 commit 0964d17
Showing 1 changed file with 64 additions and 42 deletions.
106 changes: 64 additions & 42 deletions script.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#!/bin/sh
# Alacritty Color Export
# Version 0.1.1
# pywal2alacritty - get colors from Pywal and apply to Alacritty config
# v0.2.0
# github.com/egeesin
#
# Exports generated Wal colors to Alacritty config
# WARNING: Don't forget to backup your Alacritty config
# before execute this script!
#
# Dependencies: grep, sed
# Deps: grep, sed
# Usage: ./script.sh
# ./script.sh <config yml>
# ./script.sh <config toml>

# Function to display error and quit
die() {
printf "ERR: %s\n" "$1" >&2
exit 1
}

DEFAULT_MACOS_CONFIG="$HOME"/.config/alacritty/alacritty.yml
DEFAULT_MACOS_CONFIG="$HOME"/.config/alacritty/alacritty.toml

# Wal generates a shell script that defines color0..color15
SRC="$HOME"/.cache/wal/colors.sh
Expand Down Expand Up @@ -58,56 +54,82 @@ trap 'rm $tempfile' INT TERM EXIT

# Delete existing color declarations generated by this script
# If begin comment exists
if grep -q '^# BEGIN ACE' "$CFG"; then
if grep -q '^# BEGIN WAL' "$CFG"; then
# And if end comment exists
if grep -q '^# END ACE' "$CFG"; then
if grep -q '^# END WAL' "$CFG"; then
# Delete contents of the block
printf "Existing generated colors found, replacing new colors...\n"
sed '/^# BEGIN ACE/,/^# END ACE/ {
/^# BEGIN ACE/! { /^# END ACE/!d; }
sed '/^# BEGIN WAL/,/^# END WAL/ {
/^# BEGIN WAL/! { /^# END WAL/!d; }
}' "$CFG" > "$tempfile" \
&& cat "$tempfile" > "$CFG"
# If no end comment, don't do anything
else
die "No '# END ACE' comment found, please ensure it is present."
die "No '# END WAL' comment found, please ensure it is present."
fi
# If no begin comment found
else
# Don't do anything and notify user if there's an end comment in the file
! grep -q '^# END ACE' "$CFG" || die "Found '# END ACE' comment, but no '# BEGIN ACE' comment found. Please ensure it is present."
! grep -q '^# END WAL' "$CFG" || die "Found '# END WAL' comment, but no '# BEGIN WAL' comment found. Please ensure it is present."
printf "There's no existing 'generated' colors, adding comments...\n";
printf '# BEGIN ACE\n# END ACE' >> "$CFG";
printf '# BEGIN WAL\n# END WAL' >> "$CFG";
fi

# Write new color definitions
# We know $colorX is unset, we set it by sourcing above
# shellcheck disable=SC2154
{ sed "/^# BEGIN ACE/ r /dev/stdin" "$CFG" > "$tempfile" <<EOF
colors:
primary:
background: '$color0'
foreground: '$color7'
cursor:
text: '$color0'
cursor: '$color7'
normal:
black: '$color0'
red: '$color1'
green: '$color2'
yellow: '$color3'
blue: '$color4'
magenta: '$color5'
cyan: '$color6'
white: '$color7'
bright:
black: '$color8'
red: '$color9'
green: '$color10'
yellow: '$color11'
blue: '$color12'
magenta: '$color13'
cyan: '$color14'
white: '$color15'
{ sed "/^# BEGIN WAL/ r /dev/stdin" "$CFG" > "$tempfile" <<EOF
[colors.primary]
background = '$color0'
foreground = '$color7'
[colors.cursor]
text = '$color0' # Apply background color to color of text inside cursor
cursor = '$color7' # Apply foreground color to color of cursor
[colors.vi_mode_cursor]
text = '$color0' # Same as above
cursor = '$color7'
[colors.search.matches]
foreground = '$color0' # Same as above
background = '$color15' # Apply bright/white color to bg color of matching search
[colors.search.focused_match]
foreground = 'CellBackground'
background = 'CellForeground'
[colors.line_indicator]
foreground = 'None'
background = 'None'
[colors.footer_bar]
foreground = '$color8'
background = '$color7'
[colors.selection]
text = 'CellBackground'
background = 'CellForeground'
[colors.normal]
black = '$color0'
red = '$color1'
green = '$color2'
yellow = '$color3'
blue = '$color4'
magenta = '$color5'
cyan = '$color6'
white = '$color7'
[colors.bright]
black = '$color8'
red = '$color9'
green = '$color10'
yellow = '$color11'
blue = '$color12'
magenta = '$color13'
cyan = '$color14'
white = '$color15'
EOF
} && cat "$tempfile" > "$CFG" \
&& rm "$tempfile"
Expand Down

0 comments on commit 0964d17

Please sign in to comment.