zsh-plugin
The zsh-plugin installation method clones Git repositories for zsh plugins and automatically configures them to be sourced in your shell. This is useful for installing plugins that are not available via package managers.
Configuration
Section titled “Configuration”Basic Usage
Section titled “Basic Usage”GitHub Shorthand
Section titled “GitHub Shorthand”The simplest way to install a plugin from GitHub:
import { defineTool } from "@alexgorbatchev/dotfiles";
export default defineTool((install) => install("zsh-plugin", { repo: "jeffreytse/zsh-vi-mode", }),);The plugin is automatically sourced - no additional configuration needed!
Full Git URL
Section titled “Full Git URL”For plugins hosted elsewhere (GitLab, Bitbucket, private repos):
import { defineTool } from "@alexgorbatchev/dotfiles";
export default defineTool((install) => install("zsh-plugin", { url: "https://gitlab.com/user/custom-plugin.git", }),);Install Parameters
Section titled “Install Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
repo | string | No* | GitHub repository shorthand (e.g., user/repo) |
url | string | No* | Full Git URL (e.g., https://github.com/user/repo.git) |
pluginName | string | No | Custom plugin directory name (defaults to repository name) |
source | string | No | Explicit source file path (auto-detected if not specified) |
auto | boolean | No | Auto-install during generate command (default: true) |
* Either repo or url must be provided.
Auto-Install Behavior
Section titled “Auto-Install Behavior”By default (auto: true), zsh plugins are automatically installed during the dotfiles generate command. This means:
- When you run
dotfiles generate, plugins withauto: trueare cloned/updated - The plugin’s
sourcecommand is automatically added to your shell init - No separate
dotfiles installstep is needed for these plugins
To disable auto-installation and require explicit dotfiles install:
import { defineTool } from "@alexgorbatchev/dotfiles";
export default defineTool((install) => install("zsh-plugin", { repo: "jeffreytse/zsh-vi-mode", auto: false, // Requires explicit `dotfiles install` }),);Custom Plugin Name
Section titled “Custom Plugin Name”Use pluginName when you want the plugin directory name to differ from the repository name:
import { defineTool } from "@alexgorbatchev/dotfiles";
export default defineTool((install) => install("zsh-plugin", { repo: "jeffreytse/zsh-vi-mode", pluginName: "vi-mode", // Cloned to plugins/vi-mode instead of plugins/zsh-vi-mode }),);Explicit Source File
Section titled “Explicit Source File”If the plugin’s source file doesn’t follow standard naming conventions, specify it explicitly:
import { defineTool } from "@alexgorbatchev/dotfiles";
export default defineTool((install) => install("zsh-plugin", { repo: "some-org/some-plugin", source: "custom-init.zsh", // Use this file instead of auto-detection }),);How It Works
Section titled “How It Works”- Clone: The repository is cloned with
--depth 1to minimize download size - Detect: The plugin’s source file is auto-detected (e.g.,
*.plugin.zsh) - Source: A
sourcecommand is automatically added to your shell init - Update: On subsequent runs,
git pull --ff-onlyupdates the plugin - Version: Version is determined from git tags (e.g.,
v0.1.0) or commit hash (e.g.,abc1234)
Auto-detected Source Files
Section titled “Auto-detected Source Files”The installer checks for these files in order:
{pluginName}.plugin.zsh{pluginName}.zshinit.zshplugin.zsh{pluginName}.zsh-theme
Adding Environment Variables
Section titled “Adding Environment Variables”Use .zsh() to add environment variables or other shell configuration:
import { defineTool } from "@alexgorbatchev/dotfiles";
export default defineTool((install) => install("zsh-plugin", { repo: "jeffreytse/zsh-vi-mode", }).zsh((shell) => shell.env({ ZVM_VI_INSERT_ESCAPE_BINDKEY: "jj", ZVM_CURSOR_STYLE_ENABLED: "false", }), ),);The environment variables are set before the plugin is sourced, allowing you to configure the plugin’s behavior.
Troubleshooting
Section titled “Troubleshooting”Update fails
Section titled “Update fails”If git pull --ff-only fails, you may have local changes. Delete the plugin directory and reinstall, or manually reset it:
cd ~/.dotfiles-generated/plugins/<plugin-name>git reset --hard origin/HEADRelated
Section titled “Related”- Manual Installation - For plugins requiring custom setup
- Shell Integration - How shell configs are generated