Skip to content

andre-kotake/nvim-chezmoi

Repository files navigation

nvim-chezmoi

A NeoVim plugin written in Lua that integrates with chezmoi.

Requirements

Features

  • Interface for chezmoi commands.
  • Sets the appropriate filetype for a source file based on the target file name.
  • Preview the executed template in a new window.
  • Apply all files or specified ones.
  • telescope extensions for files in source directory.

Installation

First, ensure that chezmoi is in your PATH.

Then, install nvim-chezmoi with your favorite plugin manager. You'll need both plenary and telescope installed too.

With lazy.nvim

  return {
    "andre-kotake/nvim-chezmoi",
    dependencies = {
      { "nvim-lua/plenary.nvim" },
      { "nvim-telescope/telescope.nvim" },
    },
    opts = { 
      -- Your custom config 
    },
    config = function(_, opts)
      require("nvim-chezmoi").setup(opts)
    end,
  }

Configuration

Default configuration values for nvim-chezmoi:

  {
    -- Show extra debug messages.
    debug = false,
    -- chezmoi source path. Defaults to the result of `chezmoi source-path`
    -- Change this only if your dotfiles live in a different directory.
    source_path = nil,
    edit = {
      -- Automatically apply file on save. Can be one of: "auto", "confirm" or "never"
      apply_on_save = "never",
    },
    window = {
      -- Changes the layout for executed template window.
      execute_template = {
        relative = "editor",
        width = vim.o.columns,
        height = vim.o.lines,
        row = 0,
        col = 0,
        style = "minimal",
        border = "single",
      },
    },
  }

Usage

User Commands

Global

  • :ChezmoiApply [file...]: Applies changes to source files. You may specify optional file args to apply them only.
  • :ChezmoiEdit [file...]: Opens the source file from current buffer target file.You may specify optional [file] argument if you want to open that instead. Example: :ChezmoiEdit ~/.bashrc Encrypted files have partial supported. Tested and working fine for gpg encryption as long as you have args: ["--quiet"] in your chezmoi configuration.
  • :ChezmoiManaged: List source managed files with telescope.
  • :ChezmoiFiles: List special chezmoi files in source directory with telescope.

Source files only

  • :ChezmoiExecuteTemplate: Preview the executed template in a new buffer. Only applies for files with the ".tmpl" extension.
  • :ChezmoiDetectFileType: Detects the correct filetype for the opened source file. Not really much use since it does it by default whenever you open a file.

Telescope Extension

  • :Telescope nvim-chezmoi managed: Lists managed files. Same as :ChezmoiManaged.
  • :Telescope nvim-chezmoi special_files: Lists all chezmoi special files under source directory. Same as ChezmoiFiles.

To do

  • Refactor Telescope extension.

Acknowledgements

Stuff that helped me or inspired this:

For cool alternatives:

Contributing

All contributions and suggestions are welcome; Feel free to open an issue or pull request.

License

MIT

About

A NeoVim plugin that integrates with chezmoi.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages