From 5a691c23160a3c8fb69ec13b675e18f81ed1063e Mon Sep 17 00:00:00 2001 From: Ivan Milov <522518+ivanmilov@users.noreply.github.com> Date: Sat, 20 Feb 2021 22:12:40 +0100 Subject: [PATCH] add support for alacritty --- apply-alacritty.py | 23 ++++++++++++++++ apply-colors.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100755 apply-alacritty.py diff --git a/apply-alacritty.py b/apply-alacritty.py new file mode 100755 index 0000000..4ce475d --- /dev/null +++ b/apply-alacritty.py @@ -0,0 +1,23 @@ +import io +import json +import sys +from appdirs import user_config_dir +from ruamel.yaml import YAML # use ruamel.yaml to preserve comments in config + + +yaml = YAML() +conf = user_config_dir('alacritty') + "/alacritty.yml" +# Read alacritty config +with open(conf, 'r') as stream: + data_loaded = yaml.load(stream) + +js = json.loads(sys.argv[1]) + +# Use update to not remove existing comments +data_loaded['colors']['primary'].update(js['colors']['primary']) +data_loaded['colors']['normal'].update(js['colors']['normal']) +data_loaded['colors']['bright'].update(js['colors']['bright']) + +# Write alacritty config +with io.open(conf, 'w', encoding='utf8') as outfile: + yaml.dump(data_loaded, outfile) diff --git a/apply-colors.sh b/apply-colors.sh index 1486b2c..8f6127a 100755 --- a/apply-colors.sh +++ b/apply-colors.sh @@ -367,6 +367,67 @@ apply_cygwin() { echo "Done - please reopen your Cygwin terminal to see the changes" } +apply_alacritty() { + # | + # | Applying values on Alacritty + # | =========================================== + + json_str="\ + { \ + \"colors\": \ + {\ + \"primary\":\ + {\ + \"background\": \"$BACKGROUND_COLOR\",\ + \"foreground\": \"$FOREGROUND_COLOR\"\ + },\ + \"normal\":\ + {\ + \"black\": \"$COLOR_01\",\ + \"red\": \"$COLOR_02\",\ + \"green\": \"$COLOR_03\",\ + \"yellow\":\"$COLOR_04\",\ + \"blue\":\"$COLOR_05\",\ + \"magenta\": \"$COLOR_06\",\ + \"cyan\":\"$COLOR_07\",\ + \"white\": \"$COLOR_08\"\ + },\ + \"bright\":\ + {\ + \"black\":\"$COLOR_09\",\ + \"red\":\"$COLOR_10\",\ + \"green\":\"$COLOR_11\",\ + \"yellow\": \"$COLOR_12\",\ + \"blue\": \"$COLOR_13\",\ + \"magenta\":\"$COLOR_14\",\ + \"cyan\": \"$COLOR_15\",\ + \"white\":\"$COLOR_16\"\ + } \ + }\ + }" + + SCRIPT_PATH="${SCRIPT_PATH:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}" + PARENT_PATH="$(dirname "${SCRIPT_PATH}")" + + # Allow developer to change url to forked url for easier testing + # IMPORTANT: Make sure you export this variable if your main shell is not bash + BASE_URL=${BASE_URL:-"https://raw.githubusercontent.com/Mayccoll/Gogh/master"} + + + if [[ -e "${SCRIPT_PATH}/apply-alacritty.py" ]]; then + python3 "${SCRIPT_PATH}/apply-alacritty.py" "$json_str" + else + if [[ "$(uname)" = "Darwin" ]]; then + # OSX ships with curl and ancient bash + python3 -c "$(curl -so- "${BASE_URL}/apply-alacritty.py")" "$json_str" + else + # Linux ships with wget + python3 -c "$(wget -qO- "${BASE_URL}/apply-alacritty.py")" "$json_str" + fi + fi + +} + apply_darwin() { # | # | Applying values on iTerm2 @@ -713,6 +774,10 @@ case "${TERMINAL}" in apply_xfce4-terminal ;; + alacritty ) + apply_alacritty + ;; + * ) printf '%s\n' \ "Unsupported terminal!" \