Skip to content

Instantly share code, notes, and snippets.

@AvinashReddy3108
Last active April 12, 2023 08:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AvinashReddy3108/d6889f7747843d8c4e67aba68c4469db to your computer and use it in GitHub Desktop.
Save AvinashReddy3108/d6889f7747843d8c4e67aba68c4469db to your computer and use it in GitHub Desktop.
A dirty script to convert Gogh Terminal script to the Termux colorscheme format
#!/usr/bin/env bash
current=1
current_dir=$(pwd)
total=$(ls ../Gogh/themes/*.sh | wc -l)
cd ../Gogh && git pull --ff-only; cd $current_dir
for x in ../Gogh/themes/*.sh
do
filename=$(basename -- "$x")
scheme_file="${filename%.*}"
scheme_name=$(grep -Po '(?<=export PROFILE_NAME=).*' "$x" | tr -d '"')
echo -n -e "[$current/$total] Processing $scheme_name, please wait!\n\r"
current=$(($current + 1))
# Generate header, for credits.
cat > "$scheme_file".properties <<- EOM
# ===============================================================
# Color Scheme: $scheme_name
# Source: https://github.com/Mayccoll/Gogh/blob/master/themes/$scheme_file.sh
# Credits: https://github.com/Mayccoll/Gogh/graphs/contributors
# ===============================================================
EOM
# Get only the 'export' lines from the file.
grep "^export" "$x" >> "$scheme_file".properties
# Delete 'export' from each line.
sed -i 's/^export //' "$scheme_file".properties
# Remove inline comments from each line.
sed -i -e 's/[ ]# .*$//' -e 's/\(#\)*$//g' "$scheme_file".properties
# Remove quotes from all entries.
sed -i -e 's/"//g' "$scheme_file".properties
sed -i -e "s/'//g" "$scheme_file".properties
# Hardcode all 'smart' $COLOR_xx substitutions.
for i in {00..21}
do
xcolor_val=$(grep -Po "(?<=COLOR_$i=).*" "$scheme_file".properties)
sed -i -e "s/$\COLOR_$i/$xcolor_val/" "$scheme_file".properties
done
# Hardcode a few remaining substitutions.
# -> $FOREGROUND_COLOR
fg_val=$(grep -Po "(?<=FOREGROUND_COLOR=).*" "$scheme_file".properties)
sed -i -e "s/$\FOREGROUND_COLOR/$fg_val/" "$scheme_file".properties
# Remove trailing whitespace from files.
sed -i -e 's/[[:blank:]]\+$//' "$scheme_file".properties
# Convert keys (variable names) to Termux ones.
for i in {01..16}
do
sed -i -e "s/COLOR_$i/color$(($(echo "$i" | sed -e 's/^0//') - 1))/" "$scheme_file".properties
done
sed -i -e "s/BACKGROUND_COLOR/background/" "$scheme_file".properties
sed -i -e "s/FOREGROUND_COLOR/foreground/" "$scheme_file".properties
sed -i -e "s/CURSOR_COLOR/cursor/" "$scheme_file".properties
# Remove bloat keys, Termux doesn't need/use them.
sed -i -e '/^PROFILE_NAME=/d' "$scheme_file".properties
sed -i -e '/^HIGHLIGHT_FG_COLOR=/d' "$scheme_file".properties
sed -i -e '/^HIGHLIGHT_BG_COLOR=/d' "$scheme_file".properties
sed -i -e '/^USE_SYS_TRANSPARENCY=/d' "$scheme_file".properties
# Remove remaining inline comments.
cut -d '#' -f 1,2 "$scheme_file".properties > "$scheme_file".properties.1
mv "$scheme_file".properties.1 "$scheme_file".properties
# Make sure we don't have any trailing whitespace.
sed -i -e 's/[[:blank:]]\+$//' "$scheme_file".properties
done
# Done, move to output directory.
mkdir -p out
mv -f *.properties ./out/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment