Neovim plugin to automatically adjust git env vars when syncing dotfiles using the "bare git repo" method

Compare changes

Choose any two refs to compare.

Changed files
+187 -12
.github
workflows
doc
lua
+37
.github/workflows/ci.yml
···
+
name: CI
+
on:
+
push:
+
branches:
+
- 'master'
+
pull_request:
+
branches:
+
- 'master'
+
+
jobs:
+
docs:
+
runs-on: ubuntu-latest
+
steps:
+
- uses: actions/checkout@v4
+
- name: panvimdoc
+
uses: kdheepak/panvimdoc@v4.0.1
+
with:
+
vimdoc: baredot.nvim
+
version: "Neovim >= 0.9.0"
+
demojify: true
+
treesitter: true
+
- name: Push changes
+
uses: stefanzweifel/git-auto-commit-action@v5
+
with:
+
commit_message: "chore(build): auto-generate vimdoc"
+
commit_user_name: "github-actions[bot]"
+
commit_user_email: "github-actions[bot]@users.noreply.github.com"
+
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
+
release:
+
name: release
+
needs:
+
- docs
+
runs-on: ubuntu-latest
+
steps:
+
- uses: googleapis/release-please-action@v4
+
with:
+
release-type: simple
+8
CHANGELOG.md
···
+
# Changelog
+
+
## [1.1.0](https://github.com/ejrichards/baredot.nvim/compare/v1.0.0...v1.1.0) (2024-06-17)
+
+
+
### Features
+
+
* Adding "is_enabled" lua function ([9fd8094](https://github.com/ejrichards/baredot.nvim/commit/9fd80946fe0ad6ab5147238751472e023f4a01c4))
+3 -2
README.md
···
## Commands
-
- `:BaredotInfo` - Print current status
-
- `:BaredotToggle` - Manually toggle the env vars on / off
+
- `:Baredot info` - Print current status
+
- `:Baredot toggle` - Manually toggle the env vars on / off
## Functions
- `require("baredot").info()` - Print current status
+
- `require("baredot").is_enabled()` - Returns current status as boolean
- `require("baredot").toggle()` - Manually toggle the env vars on / off
- `require("baredot").set(boolean)` - Set the env vars on / off
+37
cliff.toml
···
+
[changelog]
+
# https://keats.github.io/tera/docs/#introduction
+
body = """
+
{% for group, commits in commits | group_by(attribute="group") %}
+
=== {{ group | striptags | trim | upper_first }}
+
{% for commit in commits %}
+
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
+
{% if commit.breaking %}[**breaking**] {% endif %}\
+
{{ commit.message | upper_first }}\
+
{% endfor %}
+
{% endfor %}\n
+
"""
+
# remove the leading and trailing s
+
trim = true
+
+
[git]
+
conventional_commits = true
+
filter_unconventional = true
+
split_commits = false
+
+
# Just things end users will care about
+
commit_parsers = [
+
{ message = "^feat", group = "<!-- 0 -->๐Ÿš€ Features" },
+
{ message = "^fix", group = "<!-- 1 -->๐Ÿ› Bug Fixes" },
+
{ message = "^doc", group = "<!-- 3 -->๐Ÿ“š Documentation" },
+
{ message = "^perf", group = "<!-- 4 -->โšก Performance" },
+
{ message = "^style", group = "<!-- 5 -->๐ŸŽจ Styling" },
+
{ message = "^test", group = "<!-- 6 -->๐Ÿงช Testing" },
+
{ message = "^chore|^ci|^refactor", skip = true },
+
{ body = ".*security", group = "<!-- 8 -->๐Ÿ›ก๏ธ Security" },
+
{ message = "^revert", group = "<!-- 9 -->โ—€๏ธ Revert" },
+
{ message = ".*", group = "<!-- 10 -->๐Ÿ’ผ Other" },
+
]
+
# filter out the commits that are not matched by commit parsers
+
filter_commits = false
+
topo_order = false
+
sort_commits = "oldest"
doc/.gitkeep

This is a binary file and will not be displayed.

+76
doc/baredot.nvim.txt
···
+
*baredot.nvim.txt* For Neovim >= 0.9.0 Last change: 2024 June 18
+
+
==============================================================================
+
Table of Contents *baredot.nvim-table-of-contents*
+
+
1. Baredot |baredot.nvim-baredot|
+
- Details |baredot.nvim-baredot-details|
+
- Setup |baredot.nvim-baredot-setup|
+
- Configuration |baredot.nvim-baredot-configuration|
+
- Commands |baredot.nvim-baredot-commands|
+
- Functions |baredot.nvim-baredot-functions|
+
+
==============================================================================
+
1. Baredot *baredot.nvim-baredot*
+
+
This is a Neovim plugin to automatically adjust `git` env vars when syncing
+
dotfiles using the "bare git repo" method:
+
+
Dotfiles: Best way to store in a bare git repository
+
<https://www.atlassian.com/git/tutorials/dotfiles>
+
+
+
DETAILS *baredot.nvim-baredot-details*
+
+
When launching and when changing directory (eg. `:cd`), the plugin will detect
+
if the current directory is in a git repo by searching for a `.git` folder.
+
+
- If a `.git` folder is found, the env vars are cleared and `git` will work as normal.
+
- If a `.git` folder is not found, and we are in `$HOME`, the env vars will be adjusted to use the
+
bare git repo. This will let other git plugins function using that repo.
+
+
+
SETUP *baredot.nvim-baredot-setup*
+
+
lazy.nvim
+
+
>lua
+
{
+
"ejrichards/baredot.nvim",
+
opts = {
+
git_dir = "~/.cfg" -- Change this path
+
}
+
}
+
<
+
+
+
CONFIGURATION *baredot.nvim-baredot-configuration*
+
+
>lua
+
{
+
-- These two options set the GIT_DIR and GIT_WORK_TREE env vars
+
-- They are expanded using "vim.fn.expand"
+
git_dir = "~/.cfg",
+
git_work_tree = "~",
+
-- Filename pattern to find that will disable Baredot
+
disable_pattern = "%.git"
+
}
+
<
+
+
+
COMMANDS *baredot.nvim-baredot-commands*
+
+
- `:Baredot info` - Print current status
+
- `:Baredot toggle` - Manually toggle the env vars on / off
+
+
+
FUNCTIONS *baredot.nvim-baredot-functions*
+
+
- `require("baredot").info()` - Print current status
+
- `require("baredot").is_enabled()` - Returns current status as boolean
+
- `require("baredot").toggle()` - Manually toggle the env vars on / off
+
- `require("baredot").set(boolean)` - Set the env vars on / off
+
+
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
+
+
vim:tw=78:ts=8:noet:ft=help:norl:
+22 -10
lua/baredot/commands.lua
···
end
end
+
function Commands.is_enabled()
+
return vim.env.GIT_DIR ~= nil and vim.env.GIT_WORK_TREE ~= nil
+
end
+
function Commands.toggle()
-
if vim.env.GIT_DIR == nil or vim.env.GIT_WORK_TREE == nil then
-
Commands.set(true)
-
else
-
Commands.set(false)
-
end
+
Commands.set(not Commands.is_enabled())
Commands.info()
end
function Commands.info()
-
if vim.env.GIT_DIR == nil or vim.env.GIT_WORK_TREE == nil then
-
vim.notify("Baredot mode off", vim.log.levels.INFO, { title = "baredot.nvim" });
-
else
+
if Commands.is_enabled() then
vim.notify(
"Baredot mode on: GIT_DIR=" .. vim.env.GIT_DIR .. " GIT_WORK_TREE=" .. vim.env.GIT_WORK_TREE,
vim.log.levels.INFO,
{ title = "baredot.nvim" }
);
+
else
+
vim.notify("Baredot mode off", vim.log.levels.INFO, { title = "baredot.nvim" });
end
end
function Commands.setup(opt)
options = opt
-
vim.api.nvim_create_user_command("BaredotInfo", Commands.info, { desc = "BaredotInfo" })
-
vim.api.nvim_create_user_command("BaredotToggle", Commands.toggle, { desc = "BaredotToggle" })
+
vim.api.nvim_create_user_command("Baredot", function(args)
+
local cmd = vim.trim(args.args or "")
+
if cmd == "toggle" then
+
Commands.toggle()
+
else
+
Commands.info()
+
end
+
end, {
+
desc = "Baredot",
+
nargs = "?",
+
complete = function()
+
return { "info", "toggle" }
+
end
+
})
end
return Commands
+4
lua/baredot/init.lua
···
function Baredot.toggle()
return commands.toggle()
end
+
---@return boolean
+
function Baredot.is_enabled()
+
return commands.is_enabled()
+
end
return Baredot