From 043b436ba75233624369f0256d67f2da60c6a8da Mon Sep 17 00:00:00 2001
From: "Edgar P. Burkhart" <git@edgarpierre.fr>
Date: Sat, 5 Feb 2022 17:48:47 +0100
Subject: [PATCH] Initial code and config files

---
 .gitignore              | 152 ++++++++++++++++++++++++++++++++++++++++
 autoconfig/__main__.py  |  60 ++++++++++++++++
 config.ini              |  14 ++++
 config/gitconfig        |   8 +++
 config/init.vim         |  27 +++++++
 config/kitty-theme.conf |  23 ++++++
 config/kitty.conf       |   8 +++
 pacman.list             |   2 +
 8 files changed, 294 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 autoconfig/__main__.py
 create mode 100644 config.ini
 create mode 100644 config/gitconfig
 create mode 100644 config/init.vim
 create mode 100644 config/kitty-theme.conf
 create mode 100644 config/kitty.conf
 create mode 100644 pacman.list

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d9005f2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,152 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+cover/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+.pybuilder/
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+#   For a library or package, you might want to ignore these files since the code is
+#   intended to run in multiple environments; otherwise, check them in:
+# .python-version
+
+# pipenv
+#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+#   However, in case of collaboration, if having platform-specific dependencies or dependencies
+#   having no cross-platform support, pipenv may install dependencies that don't work, or not
+#   install all needed dependencies.
+#Pipfile.lock
+
+# poetry
+#   Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
+#   This is especially recommended for binary packages to ensure reproducibility, and is more
+#   commonly ignored for libraries.
+#   https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
+#poetry.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+# pytype static type analyzer
+.pytype/
+
+# Cython debug symbols
+cython_debug/
+
+# PyCharm
+#  JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
+#  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
+#  and can be added to the global gitignore or merged into this file.  For a more nuclear
+#  option (not recommended) you can uncomment the following to ignore the entire idea folder.
+#.idea/
diff --git a/autoconfig/__main__.py b/autoconfig/__main__.py
new file mode 100644
index 0000000..99b00fd
--- /dev/null
+++ b/autoconfig/__main__.py
@@ -0,0 +1,60 @@
+import argparse
+import configparser
+import logging
+import shutil
+import subprocess
+import pathlib
+import os
+import getpass
+import tempfile
+
+
+# CLI Args Parsing
+parser = argparse.ArgumentParser(
+    description='Automatically configure ArchLinux install')
+parser.add_argument('-V', '--version', action='version', version='v0.1')
+parser.add_argument('-v', '--verbose', action='count', default=0)
+parser.add_argument('-c', '--config', type=pathlib.Path, default='config.ini',
+    help='Configuration file')
+
+args = parser.parse_args()
+
+# Config File Parsing
+config = configparser.ConfigParser()
+config.read(args.config)
+
+# Logging Setup
+logging.basicConfig()
+log = logging.getLogger('autoconfig')
+
+#   Get minimum level from CLI and File Configs
+log.setLevel(config.get('log', 'level', fallback=None))
+log.setLevel(min(
+    30-10*args.verbose, log.level,
+))
+
+# Pacman
+if config.getboolean('pacman', 'install_yay', fallback=False):
+    log.info('Installing yay')
+    with tempfile.TemporaryDirectory() as yay_folder:
+        log.info('Cloning yay')
+        subprocess.run(('git', 'clone', 'https://aur.archlinux.org/yay', yay_folder))
+        subprocess.run(('makepkg', '-rcsi'), cwd=yay_folder)
+
+if config.getboolean('pacman', 'install_pkg', fallback=False):
+    with open(config.get('pacman', 'pkg_list', fallback=''), 'r') as pkg_file:
+        pkg_list = pkg_file.read().splitlines()
+    log.info('Installing packages')
+    subprocess.run(('yay', '-Syu', *pkg_list))
+
+# Config files
+if 'config' in config:
+    log.info('Copying config files')
+    config_root = pathlib.Path(config['config'].pop('root'))
+    for item in config['config'].values():
+        src, dst = item.split(':')
+        src = config_root.joinpath(src)
+        dst = pathlib.Path(dst).expanduser()
+        log.debug(f'Copying {src} -> {dst}')
+        dst.parent.mkdir(exist_ok=True)
+        shutil.copy2(src, dst)
diff --git a/config.ini b/config.ini
new file mode 100644
index 0000000..c842cce
--- /dev/null
+++ b/config.ini
@@ -0,0 +1,14 @@
+[pacman]
+install_yay = True
+install_pkg = False
+pkg_list = pacman.list
+
+[config]
+root = config
+kitty = kitty.conf:~/.config/kitty/kitty.conf
+kitty-theme = kitty-theme.conf:~/.config/kitty/theme.conf
+neovim = init.vim:~/.config/nvim/init.vim
+git = gitconfig:~/.gitconfig
+
+[log]
+level = INFO
diff --git a/config/gitconfig b/config/gitconfig
new file mode 100644
index 0000000..d35a81d
--- /dev/null
+++ b/config/gitconfig
@@ -0,0 +1,8 @@
+[user]
+	name = Edgar P. Burkhart
+	email = git@edgarpierre.fr
+	signingkey = 9833D3C5A25BD227
+[commit]
+	gpgsign = true
+[tag]
+	gpgsign = true
diff --git a/config/init.vim b/config/init.vim
new file mode 100644
index 0000000..1e91844
--- /dev/null
+++ b/config/init.vim
@@ -0,0 +1,27 @@
+"Clipboard
+set clipboard+=unnamedplus
+
+"Tabulations
+set tabstop=2
+set shiftwidth=2
+
+set noexpandtab
+
+"Mouse
+set mouse=a
+
+"Search
+set ignorecase
+
+"Completion
+set wildmode=longest,list,full
+
+"Line numbers
+set number
+
+"Color column
+set cc=80
+
+"Split side
+set splitright
+set splitbelow
diff --git a/config/kitty-theme.conf b/config/kitty-theme.conf
new file mode 100644
index 0000000..a491f3d
--- /dev/null
+++ b/config/kitty-theme.conf
@@ -0,0 +1,23 @@
+# Theme ported from the Mac Terminal application.
+
+background            #79241d
+foreground            #d6c8a7
+cursor                #ffffff
+selection_background  #a4a390
+color0                #000000
+color8                #545454
+color1                #ff3e00
+color9                #ba0000
+color2                #00ba00
+color10               #00ba00
+color3                #e6af00
+color11               #e6af00
+color4                #0071ff
+color12               #0071ae
+color5                #ba00ba
+color13               #ff54ff
+color6                #00baba
+color14               #54ffff
+color7                #bababa
+color15               #ffffff
+selection_foreground #79241d
diff --git a/config/kitty.conf b/config/kitty.conf
new file mode 100644
index 0000000..32158e5
--- /dev/null
+++ b/config/kitty.conf
@@ -0,0 +1,8 @@
+font_family Fira Code
+font_size 12
+include ./theme.conf
+
+map ctrl+f2 detach_window
+map ctrl+f3 detach_window new-tab
+map ctrl+shift+t new_tab_with_cwd
+map ctrl+shift+enter new_window_with_cwd
diff --git a/pacman.list b/pacman.list
new file mode 100644
index 0000000..e625f81
--- /dev/null
+++ b/pacman.list
@@ -0,0 +1,2 @@
+git
+fish
