1
0
mirror of https://github.com/Mayccoll/Gogh.git synced 2023-08-10 21:12:46 +03:00

Fix Alacritty configuration script and docs

Alacritty looks for its configuration files in a small range of folders on OSX
and other unix systems

When getting started with this project I noticed that on OSX the user_config_dir
defaults to "[/Users/username/Library/Application Support](https://github.com/ActiveState/appdirs#some-example-output)"
This location is not among the locations Alacritty looks for according to [their own docs](https://github.com/alacritty/alacritty#configuration),
so installing a theme was bit of a pain.

I moved some stuff around to make the install script a little bit smarter, I
then also created a requirements.txt file to go along with the python file to
make sure users know what dependencies work with the script.

Installation of a theme also performs destructive/constructive actions on the
main configuration file for Alacritty so I also included a little prompt for the
user to double check if they really really want to write to the config file.

Lastly I updated the installation instructions to help alacritty users get
started

Unrelated (biased) side-point:
Most Unix terminal config lives in ~/.config/your_app_name these days. `src` is
bit of a weird name for a pretty specific theme engine on someone's computer.
I'm not going to make the change here, but I would deffo reccomend updating
documentation and scripts to install Gogh to the config DIR instead.
This commit is contained in:
Peter van der Meulen 2022-11-22 22:14:47 +01:00
parent f8b6173d18
commit 4a1cee9d29
No known key found for this signature in database
GPG Key ID: 39261902B1B3760C
3 changed files with 76 additions and 12 deletions

View File

@ -57,11 +57,18 @@ bash -c "$(curl -sLo- https://git.io/vQgMr)"
mkdir -p "$HOME/src" mkdir -p "$HOME/src"
cd "$HOME/src" cd "$HOME/src"
git clone https://github.com/Gogh-Co/Gogh.git gogh git clone https://github.com/Gogh-Co/Gogh.git gogh
cd gogh/themes cd gogh
# necessary on ubuntu # necessary in the Gnome terminal on ubuntu
export TERMINAL=gnome-terminal export TERMINAL=gnome-terminal
# necessary in the Alacritty terminal
pip install -r requirements.txt
export TERMINAL=alacritty
# Enter themes dir
cd themes
# install themes # install themes
./atom.sh ./atom.sh
./dracula.sh ./dracula.sh
@ -69,6 +76,7 @@ export TERMINAL=gnome-terminal
## 💻 Terminals ## 💻 Terminals
- Alacritty - [Web](https://github.com/alacritty/alacritty)
- Cygwin - [Web](https://www.cygwin.com/) - Cygwin - [Web](https://www.cygwin.com/)
- Foot - [Web](https://codeberg.org/dnkl/foot) - Foot - [Web](https://codeberg.org/dnkl/foot)
- Gnome - [Web](https://help.gnome.org/users/gnome-terminal/stable/) - Gnome - [Web](https://help.gnome.org/users/gnome-terminal/stable/)

View File

@ -1,23 +1,77 @@
import io import io
import json import json
import sys import sys
from appdirs import user_config_dir import os
from ruamel.yaml import YAML # use ruamel.yaml to preserve comments in config from ruamel.yaml import YAML # use ruamel.yaml to preserve comments in config
def get_conf_path():
# Determine system
# When we are in some Java world do extra checks
if sys.platform.startswith('java'):
import platform
os_name = platform.java_ver()[3][0]
if os_name.startswith('Windows'): # "Windows XP", "Windows 7", etc.
system = 'win32'
else: # anything that isn't windows ("darwin", "Linux", "SunOS", "FreeBSD", "Arch", etc.)
system = 'linux2'
else:
system = sys.platform
if system == 'win32':
# In windows alacritty config can only exist in one place
alacritty_path = os.path.expandvars(r'%APPDATA%\alacritty\alacritty.yml')
if os.path.exists(alacritty_path):
return alacritty_path
else:
# If it is not win32 it can exists in only a few other places
xdg_config_home = os.getenv('XDG_CONFIG_HOME')
if xdg_config_home is not None and os.path.exists(xdg_config_home + '/alacritty/alacritty.yml'):
return xdg_config_home + "/alacritty/alacritty.yml"
if xdg_config_home is not None and os.path.exists(xdg_config_home + "/alacritty.yml"):
return xdg_config_home + "/alacritty.yml"
home = os.getenv('HOME')
if home is not None and os.path.exists(home + '/.config/alacritty/alacritty.yml'):
return home + "/.config/alacritty/alacritty.yml"
if home is not None and os.path.exists(home + '/.config/alacritty.yml'):
return home + "/.config/alacritty.yml"
if home is not None and os.path.exists(home + 'alacritty.yml'):
return home + "/alacritty.yml"
print("Could not find alacritty config file\nPlease make sure you have a file in one of the paths specified on\nhttps://github.com/alacritty/alacritty#configuration")
sys.exit(1)
# end
conf_path = get_conf_path()
yaml = YAML() yaml = YAML()
conf = user_config_dir('alacritty') + "/alacritty.yml"
# Read alacritty config # Read & parse alacritty config
with open(conf, 'r') as stream: with open(conf_path, 'r') as stream:
data_loaded = yaml.load(stream) data_loaded = yaml.load(stream)
# parse new colors
js = json.loads(sys.argv[1]) js = json.loads(sys.argv[1])
# Use update to not remove existing comments # Update yaml file
data_loaded['colors']['primary'].update(js['colors']['primary']) try:
data_loaded['colors']['normal'].update(js['colors']['normal']) # Use update to not remove existing comments
data_loaded['colors']['bright'].update(js['colors']['bright']) data_loaded['colors']['primary'].update(js['colors']['primary'])
data_loaded['colors']['normal'].update(js['colors']['normal'])
data_loaded['colors']['bright'].update(js['colors']['bright'])
except KeyError:
print("Could not find existing 'colors' settings in your alacritty.yml file\nplease make sure to uncomment\n'colors', as well as 'primary', 'normal' and 'bright'")
print("Check the example config at\nhttps://github.com/alacritty/alacritty/blob/master/alacritty.yml for more information")
sys.exit(1)
# make sure the user is okay with having their config changed
answer = input("This script will update your alacritty config at: \n" +
conf_path + "\nIt is reccomended to make a copy of this file before proceeding.\nAre you sure you want to continue? (Y/N)\n")
if not answer.lower() in ['y', 'yes']:
print("Aborted")
sys.exit(1)
# Write alacritty config # Write alacritty config
with io.open(conf, 'w', encoding='utf8') as outfile: with io.open(conf_path, 'w', encoding='utf8') as outfile:
yaml.dump(data_loaded, outfile) yaml.dump(data_loaded, outfile)

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
ruamel.yaml==0.17.21