From bbb12f136a6dec527fea5dca824393b38e19a79d Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Mon, 15 Jan 2024 19:02:33 +0000 Subject: [PATCH] refactor(core): move git module over to configz --- .gitignore | 3 +- data/common.lua | 3 ++ lib/data.lua | 18 +++++++++ manifests/configz-user.lua | 1 + modules/git.lua | 9 +++++ site-modules/core/templates/gitconfig.liquid | 40 ++++++++++++++++++++ 6 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 data/common.lua create mode 100644 lib/data.lua create mode 100644 modules/git.lua create mode 100644 site-modules/core/templates/gitconfig.liquid diff --git a/.gitignore b/.gitignore index 3079c79..9104f4b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ .resource_types info.rb .rerun.json +data/personal.lua ### Puppet Bolt ### .modules @@ -123,4 +124,4 @@ tags # Persistent undo [._]*.un~ -# End of https://www.toptal.com/developers/gitignore/api/puppet,emacs,code,vim,linux \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/puppet,emacs,code,vim,linux diff --git a/data/common.lua b/data/common.lua new file mode 100644 index 0000000..cb8c746 --- /dev/null +++ b/data/common.lua @@ -0,0 +1,3 @@ +return { + user_name = "Ade Attwood", +} diff --git a/lib/data.lua b/lib/data.lua new file mode 100644 index 0000000..3e2dab1 --- /dev/null +++ b/lib/data.lua @@ -0,0 +1,18 @@ +local data = {} + +data.lookup = function(scope, key) + local ok, module = pcall(require, string.format("data.%s", scope)) + if not ok then + configz.error(string.format("data.%s does not exist", scope)) + return "" + end + + if not module[key] then + configz.error(string.format("data.%s.%s does not exist", scope, key)) + return "" + end + + return module[key] +end + +return data diff --git a/manifests/configz-user.lua b/manifests/configz-user.lua index 93863cc..bdd6ce7 100644 --- a/manifests/configz-user.lua +++ b/manifests/configz-user.lua @@ -1,5 +1,6 @@ require "modules.bin" require "modules.clojure" +require "modules.git" require "modules.lua-lsp" require "modules.nvim" require "modules.nvm" diff --git a/modules/git.lua b/modules/git.lua new file mode 100644 index 0000000..95b4196 --- /dev/null +++ b/modules/git.lua @@ -0,0 +1,9 @@ +local data = require "lib.data" + +configz.template(os.getenv "HOME" .. "/.gitconfig", { + source = os.getenv "PWD" .. "/site-modules/core/templates/gitconfig.liquid", + data = { + user_name = data.lookup("common", "user_name"), + email = data.lookup("personal", "email"), + }, +}) diff --git a/site-modules/core/templates/gitconfig.liquid b/site-modules/core/templates/gitconfig.liquid new file mode 100644 index 0000000..4fdcf36 --- /dev/null +++ b/site-modules/core/templates/gitconfig.liquid @@ -0,0 +1,40 @@ +# +# !! DO NOT EDIT !! +# !! This file is managed by configz !! +# + +[user] + name = {{ data.user_name }} + email = {{ data.email }} + +[core] + editor = nvim + autocrlf = input + +[merge] + conflictstyle = diff3 + +[rerere] + enabled = true + +[push] + default = current + +[pager] + diff = delta + log = delta + reflog = delta + show = delta + +[interactive] + diffFilter = delta --color-only + +[delta] + line-numbers = true + navigate = true + hunk-header-style = raw + hunk-header-decoration-style = ul + file-modified-label = "modified:" + file-removed-label = "removed:" + file-added-label = "added:" + file-renamed-label = "renamed:"