From f4bceaac02a0e8b5025293a2dd1ff317207afe38 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Thu, 9 Apr 2026 17:30:26 -0600 Subject: [PATCH] feat: initial release --- .github/FUNDING.yml | 1 + .github/ISSUE_TEMPLATE/bug_report.md | 21 +++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 16 +++++++++++ .github/workflows/ci.yml | 30 +++++++++++++++++++++ .gitignore | 6 +++++ CHANGELOG.md | 14 ++++++++++ LICENSE | 21 +++++++++++++++ README.md | 33 +++++++++++++++++++++++ doc/tiny-mkpath.txt | 18 +++++++++++++ lua/tiny-mkpath/init.lua | 16 +++++++++++ plugin/tiny-mkpath.lua | 1 + scripts/minimal_init.lua | 4 +++ scripts/test.sh | 11 ++++++++ selene.toml | 1 + stylua.toml | 4 +++ tests/test_init.lua | 18 +++++++++++++ vim.toml | 2 ++ 17 files changed, 217 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 doc/tiny-mkpath.txt create mode 100644 lua/tiny-mkpath/init.lua create mode 100644 plugin/tiny-mkpath.lua create mode 100644 scripts/minimal_init.lua create mode 100755 scripts/test.sh create mode 100644 selene.toml create mode 100644 stylua.toml create mode 100644 tests/test_init.lua create mode 100644 vim.toml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..d2b37e7 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: swaits diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..1865fe3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,21 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Environment** +- Neovim version: +- OS: +- Config (if relevant): diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..8b76998 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,16 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' +--- + +**Is your feature request related to a problem?** +A clear and concise description of what the problem is. + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Additional context** +Add any other context about the feature request here. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..dea83c1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: JohnnyMorganz/stylua-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: --check lua/ plugin/ + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Neovim + run: | + wget -q https://github.com/neovim/neovim/releases/download/v0.12.0/nvim-linux-x86_64.appimage -O /tmp/nvim.appimage + chmod +x /tmp/nvim.appimage + /tmp/nvim.appimage --appimage-extract > /dev/null 2>&1 + echo "$PWD/squashfs-root/usr/bin" >> $GITHUB_PATH + - name: Run tests + run: ./scripts/test.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..009393c --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.swp +*.swo +*~ +.DS_Store +tags +deps/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..78da348 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.1.0] - 2026-04-09 + +### Added + +- Initial release + +[0.1.0]: https://github.com/swaits/tiny-mkpath.nvim/releases/tag/v0.1.0 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1c20050 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Stephen Waits + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ed2bfa6 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# tiny-mkpath.nvim + +A tiny plugin for Neovim 0.12+ that automatically creates parent directories +when saving a file. + +Zero config. ~12 lines of Lua. + +## Features + +- Auto-creates missing parent directories on save +- Skips remote URLs (e.g. `scp://`, `ftp://`) +- Works out of the box — no setup call required + +## Requirements + +- Neovim >= 0.12 + +## Installation + +Add to your `vim.pack.add()` call: + +```lua +"https://github.com/swaits/tiny-mkpath.nvim", +``` + +## How it works + +On `BufWritePre`, if the parent directory doesn't exist, it creates it +with `mkdir -p` semantics. So `:w brand/new/path/file.lua` just works. + +## License + +[MIT](LICENSE) diff --git a/doc/tiny-mkpath.txt b/doc/tiny-mkpath.txt new file mode 100644 index 0000000..5f108c0 --- /dev/null +++ b/doc/tiny-mkpath.txt @@ -0,0 +1,18 @@ +*tiny-mkpath.txt* Auto-create parent directories on save + +Author: Stephen Waits +License: MIT + +============================================================================== +CONTENTS *tiny-mkpath-contents* + + 1. Introduction ............................ |tiny-mkpath-introduction| + +============================================================================== +1. INTRODUCTION *tiny-mkpath-introduction* + +tiny-mkpath.nvim automatically creates parent directories when saving a +file. No configuration needed — just install and go. + +============================================================================== +vim:tw=78:ts=8:ft=help:norl: diff --git a/lua/tiny-mkpath/init.lua b/lua/tiny-mkpath/init.lua new file mode 100644 index 0000000..acdaa03 --- /dev/null +++ b/lua/tiny-mkpath/init.lua @@ -0,0 +1,16 @@ +local M = {} + +function M.setup() + vim.api.nvim_create_autocmd("BufWritePre", { + group = vim.api.nvim_create_augroup("tiny-mkpath", { clear = true }), + callback = function(event) + if event.match:match("^%w%w+://") then + return + end + local file = vim.uv.fs_realpath(event.match) or event.match + vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") + end, + }) +end + +return M diff --git a/plugin/tiny-mkpath.lua b/plugin/tiny-mkpath.lua new file mode 100644 index 0000000..9d6ee3a --- /dev/null +++ b/plugin/tiny-mkpath.lua @@ -0,0 +1 @@ +require("tiny-mkpath").setup() diff --git a/scripts/minimal_init.lua b/scripts/minimal_init.lua new file mode 100644 index 0000000..2089786 --- /dev/null +++ b/scripts/minimal_init.lua @@ -0,0 +1,4 @@ +-- Minimal init for testing tiny-mkpath.nvim +vim.opt.rtp:prepend(".") +vim.opt.rtp:prepend("deps/mini.nvim") +vim.cmd("runtime plugin/tiny-mkpath.lua") diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..f54b001 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Clone mini.nvim for test framework (if not cached) +if [ ! -d deps/mini.nvim ]; then + mkdir -p deps + git clone --depth 1 https://github.com/echasnovski/mini.nvim deps/mini.nvim +fi + +# Run tests +nvim --headless -u scripts/minimal_init.lua -c "lua require('mini.test').setup(); MiniTest.run_file('tests/test_init.lua')" diff --git a/selene.toml b/selene.toml new file mode 100644 index 0000000..d03ab0a --- /dev/null +++ b/selene.toml @@ -0,0 +1 @@ +std = "vim" diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..9218af5 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,4 @@ +column_width = 100 +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" diff --git a/tests/test_init.lua b/tests/test_init.lua new file mode 100644 index 0000000..f322634 --- /dev/null +++ b/tests/test_init.lua @@ -0,0 +1,18 @@ +local T = MiniTest.new_set() +local eq = MiniTest.expect.equality + +T["setup"] = MiniTest.new_set() + +T["setup"]["creates augroup"] = function() + local groups = vim.api.nvim_get_autocmds({ group = "tiny-mkpath" }) + eq(#groups > 0, true) +end + +T["setup"]["is idempotent"] = function() + require("tiny-mkpath").setup() + require("tiny-mkpath").setup() + local groups = vim.api.nvim_get_autocmds({ group = "tiny-mkpath" }) + eq(#groups > 0, true) +end + +return T diff --git a/vim.toml b/vim.toml new file mode 100644 index 0000000..0fa5c4f --- /dev/null +++ b/vim.toml @@ -0,0 +1,2 @@ +[vim] +any = true