From d7c7fa991497505492c6e4c1218f26d565de5db0 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Mon, 15 Jan 2024 19:26:48 +0000 Subject: [PATCH] feat(sapling): get everything setup --- manifests/configz-user.lua | 1 + modules/sapling.lua | 13 ++++++ .../core/files/oh-my-zsh/custom/sapling.zsh | 40 +++++++++++++++++++ .../core/templates/sapling.conf.liquid | 27 +++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 modules/sapling.lua create mode 100644 site-modules/core/files/oh-my-zsh/custom/sapling.zsh create mode 100644 site-modules/core/templates/sapling.conf.liquid diff --git a/manifests/configz-user.lua b/manifests/configz-user.lua index bdd6ce7..9767da3 100644 --- a/manifests/configz-user.lua +++ b/manifests/configz-user.lua @@ -4,5 +4,6 @@ require "modules.git" require "modules.lua-lsp" require "modules.nvim" require "modules.nvm" +require "modules.sapling" require "modules.tmux" require "modules.zsh" diff --git a/modules/sapling.lua b/modules/sapling.lua new file mode 100644 index 0000000..15424eb --- /dev/null +++ b/modules/sapling.lua @@ -0,0 +1,13 @@ +local data = require "lib.data" + +local config_dir = os.getenv "HOME" .. "/.config/sapling" + +configz.directory(config_dir); + +configz.template(config_dir .. "/sapling.conf", { + source = os.getenv "PWD" .. "/site-modules/core/templates/sapling.conf.liquid", + data = { + user_name = data.lookup("common", "user_name"), + email = data.lookup("personal", "email"), + }, +}) diff --git a/site-modules/core/files/oh-my-zsh/custom/sapling.zsh b/site-modules/core/files/oh-my-zsh/custom/sapling.zsh new file mode 100644 index 0000000..d4f65bf --- /dev/null +++ b/site-modules/core/files/oh-my-zsh/custom/sapling.zsh @@ -0,0 +1,40 @@ +# Alias sl to s. This is so we can keep the workflow much the same as git. You +# can mostly replace `g` with `s` and you are using sapling instead of git. +alias s="\\sl" +alias sl="sl log --remote -l25 -T '\\033[31m{node|short} \\033[0;34;3m{desc|firstline}\\033[0m \\033[3;32m{date|age} \\033[35;1;3mby {author|person} {if(github_pull_request_number, \"\033[31mPR #{github_pull_request_number}\")}\n' | tac" + +function sl-convert() { + if ! [ -d .git ]; then + echo "Not a git repository. You can only convert a git repo in to a sapling" + return 1 + fi + + if [ -s .sl ]; then + echo "Already converted to sapling." + return 1 + fi + + \sl clone --git "file://${PWD}/.git" .tmp && mv .tmp/.sl . && rm -rf .tmp + + if [[ "$(git remote get-url --all origin)" == *"github.com"* ]]; then + local new_path="$(git remote get-url --all origin | sed 's/git@github.com:/https:\/\/github.com\//')" + + echo "" + echo "Setting sapling path to '${new_path}'" + + \sl paths --add default "${new_path}" + else + echo "" + echo "[WARNING] Not a github url, you will need to set your path manually" + echo "" + fi + + echo "" + echo "" + echo "Converted yor git repo to a sapling repo." + echo "" + echo "Please run 'sl log' to ensure the command has worked. You will also need to" + echo "give 'sl config' a check to ensure your path has been set correctly. Then you" + echo "can remove the .git directory" +} + diff --git a/site-modules/core/templates/sapling.conf.liquid b/site-modules/core/templates/sapling.conf.liquid new file mode 100644 index 0000000..514ea55 --- /dev/null +++ b/site-modules/core/templates/sapling.conf.liquid @@ -0,0 +1,27 @@ +# +# !! DO NOT EDIT !! +# !! This file is managed by configz !! +# + +[ui] +# name and email, e.g. +username = {{ data.user_name }} <{{ data.email }}> + +# Don't let the sl cli colors interfere with the delta colors. The diff +# highlighting dose not work well when the two colors are conflicting each +# other. +# +# uncomment to disable color in command output +# (see 'sl help color' for details) +color = never + +# uncomment to disable command output pagination +# (see 'sl help pager' for details) +#paginate = always + +# User delta as the pager so that the diff is highlighted nicely.in the +# terminal. This give a better diff coloring than the built in sl pager, also +# keeps things looking the same as git so I can keep the familiarity when +# switching between git and sl. +[pager] +pager = delta