From 48de1e1d9780cb41c3a3416dc5ebd9f9e4d7fc4f Mon Sep 17 00:00:00 2001 From: Aleksander Cynarski Date: Sun, 15 Aug 2021 15:22:00 +0200 Subject: [PATCH] bin --- bin/alawal.sh | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 bin/alawal.sh diff --git a/bin/alawal.sh b/bin/alawal.sh new file mode 100755 index 0000000..827f591 --- /dev/null +++ b/bin/alawal.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# Alacritty Color Export +# Version 0.1.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: bash, grep, sed +# Usage: ./script.sh +# ./script.sh + +# Get Wal color file +SRC=${HOME}"/.cache/wal/colors" +[[ ! -e $SRC ]] && echo "ERR: Wal colors not found, exiting script. Did you executed Wal before?" && exit 0 +[[ -e $SRC ]] && echo "Colors found, source ready." + +READLINK=$( command -v greadlink | command -v readlink ) + +# Get config file +if [[ $1 ]]; then + # Check path syntax here + [[ -e $1 ]] && echo "Config found, destination ready."; CFG=$1 + [[ -L $1 ]] && echo "Following symlink to config..." && CFG=$($READLINK -f $1) + [[ ! -e $1 ]] && echo "ERR: Selected config doesn't exist, exiting script." && exit 0 +else + # Default config path in Mac systems + [[ -e ${HOME}"/.config/alacritty/alacritty.yml" ]] && echo "Config found, destination ready." && CFG=${HOME}"/.config/alacritty/alacritty.yml" + [[ -L ${HOME}"/.config/alacritty/alacritty.yml" ]] && echo "Following symlink to config..." && CFG=$($READLINK -f ${HOME}"/.config/alacritty/alacritty.yml") + [[ ! -e $CFG ]] && echo "ERR: Alacritty config not found, exiting script." && exit 0 +fi + +# Get and convert hex colors from Wal cache +index=1 +for line in $(grep -oE '[0-9a-fA-F]{6}' "$SRC") +do + regex='[0-9a-fA-F]{6}' + if [[ $line =~ $regex ]] + then + eval "color$index=0x$line" + index=$((index+1)); + fi +done + +# Delete existing color declerations (generated by this script) +if grep -q '^# BEGIN ACE' "$CFG"; then + echo "Existing 'generated' colors found, replacing new colors...'" + sed -i -e '/^# BEGIN ACE/,/^# END ACE/{/^# BEGIN ACE/!{/^# END ACE/!d;};}' "$CFG" +# ^^^ There's something wrong with this command. If BEGIN ACE comment +# doesn't exist but END ACE, just deletes all config except END ACE line. +# In the mean time, surrounding comments must not touched, until finding +# safer version of this command. +else + echo "There's no existing 'generated' colors, adding comments..."; + echo -e '# BEGIN ACE\n# END ACE' >> "$CFG"; +fi + +# vvv This line may give error on different systems. +sed -i -e "/^# BEGIN ACE/ r /dev/stdin" "$CFG" <