|
| 1 | +# Dotcat ZSH Completion |
| 2 | + |
| 3 | +This directory contains ZSH completion scripts for the `dotcat` command. |
| 4 | + |
| 5 | +These completion files are included when you install the dotcat package. |
| 6 | + |
| 7 | +## Files |
| 8 | + |
| 9 | +- `_dotcat` - ZSH completion script (uses the Python helper) |
| 10 | +- `dotcat-completion.py` - Python helper script for extracting dotted paths |
| 11 | +- `test-completion.zsh` - Script for testing the completion locally |
| 12 | + |
| 13 | +## Quick Installation |
| 14 | + |
| 15 | +1. Copy the completion script to a directory in your $fpath: |
| 16 | + |
| 17 | +```bash |
| 18 | +# Create completion directory if it doesn't exist |
| 19 | +mkdir -p ~/.zsh/completions |
| 20 | + |
| 21 | +# Copy the completion script |
| 22 | +cp zsh/_dotcat ~/.zsh/completions/_dotcat |
| 23 | + |
| 24 | +# Make sure the directory is in your fpath |
| 25 | +echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc |
| 26 | +``` |
| 27 | + |
| 28 | +2. Install the Python helper script: |
| 29 | + |
| 30 | +```bash |
| 31 | +# Copy to a directory in your PATH |
| 32 | +mkdir -p ~/bin |
| 33 | +cp zsh/dotcat-completion.py ~/bin/ |
| 34 | +chmod +x ~/bin/dotcat-completion.py |
| 35 | + |
| 36 | +# Make sure the directory is in your PATH |
| 37 | +echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc |
| 38 | +``` |
| 39 | + |
| 40 | +3. Reload your ZSH configuration: |
| 41 | + |
| 42 | +```bash |
| 43 | +source ~/.zshrc |
| 44 | +``` |
| 45 | + |
| 46 | +## Testing |
| 47 | + |
| 48 | +You can test the completion by typing: |
| 49 | + |
| 50 | +```bash |
| 51 | +# Test file completion |
| 52 | +dotcat [TAB] |
| 53 | + |
| 54 | +# Test dotted path completion |
| 55 | +dotcat path/to/file.json [TAB] |
| 56 | + |
| 57 | +# Test nested path completion |
| 58 | +dotcat path/to/file.json python[TAB] |
| 59 | +``` |
| 60 | + |
| 61 | +For local testing without installation, use the test script: |
| 62 | + |
| 63 | +```bash |
| 64 | +./zsh/test-completion.zsh |
| 65 | +``` |
| 66 | + |
| 67 | +## Detailed Installation Guide |
| 68 | + |
| 69 | +### Step 1: Choose a directory in your $fpath |
| 70 | + |
| 71 | +First, check your current $fpath directories: |
| 72 | + |
| 73 | +```bash |
| 74 | +echo $fpath |
| 75 | +``` |
| 76 | + |
| 77 | +Choose one of the directories from the output (e.g., |
| 78 | +`/usr/local/share/zsh/site-functions/` or `~/.zsh/completions/`). |
| 79 | + |
| 80 | +If you want to use `~/.zsh/completions/`, make sure it exists: |
| 81 | + |
| 82 | +```bash |
| 83 | +mkdir -p ~/.zsh/completions |
| 84 | +``` |
| 85 | + |
| 86 | +And add it to your $fpath in your `~/.zshrc`: |
| 87 | + |
| 88 | +```bash |
| 89 | +fpath=(~/.zsh/completions $fpath) |
| 90 | +``` |
| 91 | + |
| 92 | +### Step 2: Install the completion files |
| 93 | + |
| 94 | +Copy the completion script to your chosen directory: |
| 95 | + |
| 96 | +```bash |
| 97 | +cp zsh/_dotcat /path/to/your/chosen/directory/_dotcat |
| 98 | +``` |
| 99 | + |
| 100 | +Install the Python helper script to a directory in your PATH: |
| 101 | + |
| 102 | +```bash |
| 103 | +# System-wide installation |
| 104 | +cp zsh/dotcat-completion.py /usr/local/bin/ |
| 105 | +chmod +x /usr/local/bin/dotcat-completion.py |
| 106 | + |
| 107 | +# Or to a local bin directory |
| 108 | +mkdir -p $HOME/bin |
| 109 | +cp zsh/dotcat-completion.py $HOME/bin/ |
| 110 | +chmod +x $HOME/bin/dotcat-completion.py |
| 111 | +``` |
| 112 | + |
| 113 | +Make sure the directory is in your PATH: |
| 114 | + |
| 115 | +```bash |
| 116 | +echo 'export PATH="$HOME/bin:$PATH"' >> $HOME/.zshrc |
| 117 | +``` |
| 118 | + |
| 119 | +### Step 3: Reload your ZSH configuration |
| 120 | + |
| 121 | +```bash |
| 122 | +source ~/.zshrc |
| 123 | +``` |
| 124 | + |
| 125 | +Or restart your terminal. |
| 126 | + |
| 127 | +## Troubleshooting |
| 128 | + |
| 129 | +If completion doesn't work: |
| 130 | + |
| 131 | +1. Make sure the file is in a directory in your $fpath |
| 132 | +2. Check that the file has the correct permissions: |
| 133 | + |
| 134 | +```bash |
| 135 | +chmod 755 /path/to/_dotcat |
| 136 | +``` |
| 137 | + |
| 138 | +3. If using the Python helper, make sure it's in your PATH and executable: |
| 139 | + |
| 140 | +```bash |
| 141 | +which dotcat-completion.py |
| 142 | +chmod +x /path/to/dotcat-completion.py |
| 143 | +``` |
| 144 | + |
| 145 | +4. Run `compinit` to rebuild the completion system: |
| 146 | + |
| 147 | +```bash |
| 148 | +autoload -Uz compinit && compinit |
| 149 | +``` |
| 150 | + |
| 151 | +5. Check for any error messages when sourcing your `.zshrc` |
| 152 | + |
| 153 | +## Manual Testing |
| 154 | + |
| 155 | +If you want to test the Python helper script directly: |
| 156 | + |
| 157 | +```bash |
| 158 | +# Get top-level paths from a file |
| 159 | +dotcat-completion.py path/to/file.json |
| 160 | + |
| 161 | +# Get nested paths |
| 162 | +dotcat-completion.py path/to/file.json python |
| 163 | +dotcat-completion.py path/to/file.json python.editor |
| 164 | +``` |
| 165 | + |
| 166 | +You can also use the included test script to try the completion in a temporary |
| 167 | +environment: |
| 168 | + |
| 169 | +```bash |
| 170 | +# Run the test script |
| 171 | +./zsh/test-completion.zsh |
| 172 | +``` |
| 173 | + |
| 174 | +## How It Works |
| 175 | + |
| 176 | +The completion system works in two parts: |
| 177 | + |
| 178 | +1. The ZSH completion script (`_dotcat`) handles the command-line argument |
| 179 | + completion. |
| 180 | +2. The Python helper script (`dotcat-completion.py`) parses the structured data |
| 181 | + files and extracts the dotted paths. |
| 182 | + |
| 183 | +When you type `dotcat file.json` and press TAB, the completion script calls the |
| 184 | +Python helper to extract the possible paths from the file and presents them as |
| 185 | +completion options. |
0 commit comments