Skip to content

Commit

Permalink
added config backup and strip diacritics
Browse files Browse the repository at this point in the history
  • Loading branch information
gabsbandeira committed Feb 13, 2024
1 parent d42a81f commit 1baec2b
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions apply-terminator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import json
import os
import sys
import shutil
import datetime
import re
import unicodedata

from configobj import ConfigObj

Expand All @@ -23,9 +27,10 @@ def update_terminator_conf(terminator_conf_file_path,gogh_conf_theme,profile_opt
js = json.loads(gogh_conf_theme)

config = ConfigObj(terminator_conf_file_path)
backup_conf(terminator_conf_file_path)

if profile_options["copy_default_config"] == 'yes':
config['profiles'][profile_options["profile"]] = config['profiles']['default']
config['profiles'][profile_options["profile"]] = config['profiles']['default'].copy()
elif profile_options["copy_default_config"] == 'no':
config['profiles'][profile_options["profile"]] = {}

Expand All @@ -34,24 +39,40 @@ def update_terminator_conf(terminator_conf_file_path,gogh_conf_theme,profile_opt
config['profiles'][profile_options["profile"]]['background_color'] = js['colors']['primary']['background']
config['profiles'][profile_options["profile"]]['palette'] = js['colors']['pallete']
config.write()
print('')
print('We’ve saved your profile! Close and open your terminal to see the changes!')


def choose_profile():
profile_answer = ''
copy_default_config_answer = ''
profile_answer = input("Enter profile to update/create [default]: ")

profile_answer = strip_accents(input("Enter profile to update/create [default]: ")).strip()
if profile_answer.lower() in ['', 'default']:
profile_answer = 'default'
else:
while True:
copy_default_config_answer = input("Do you want to copy your config from default profile? [Y]: (Y/N) ")
copy_default_config_answer = input("Do you want to copy your config from default profile? [Y]: (Y/N) ").strip()
if copy_default_config_answer.lower() in ['', 'yes', 'y']:
copy_default_config_answer = 'yes'
break
elif copy_default_config_answer.lower() in ['no', 'n']:
copy_default_config_answer = 'no'
break
else:
print("Ops... Type 'Y' or 'N'.")
return {"profile": profile_answer, "copy_default_config": copy_default_config_answer}


def backup_conf(terminator_conf_file_path):
now_str = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
backup_path = f'{terminator_conf_file_path}.{now_str}'
shutil.copyfile(terminator_conf_file_path, backup_path)
print('')
print('Backup created at'+ backup_path)

def strip_accents(s):
return ''.join(c for c in unicodedata.normalize('NFD', s)
if unicodedata.category(c) != 'Mn')

main(sys.argv[1])

0 comments on commit 1baec2b

Please sign in to comment.