https://github.com/jscutlery/nx-completion
Nx workspace completion plugin for Zsh.
https://github.com/jscutlery/nx-completion
nx zsh zsh-plugin
Last synced: 5 months ago
JSON representation
Nx workspace completion plugin for Zsh.
- Host: GitHub
- URL: https://github.com/jscutlery/nx-completion
- Owner: jscutlery
- License: mit
- Created: 2021-03-19T21:11:46.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T11:54:26.000Z (almost 2 years ago)
- Last Synced: 2024-04-16T16:22:39.639Z (over 1 year ago)
- Topics: nx, zsh, zsh-plugin
- Language: Shell
- Homepage:
- Size: 114 KB
- Stars: 124
- Watchers: 6
- Forks: 14
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-zsh-plugins - nx - Completions for [nx](https://nx.dev). Requires [`jq`](https://stedolan.github.io/jq/). (Completions / ZSH on Windows)
- fucking-awesome-zsh-plugins - nx - Completions for π [nx](nx.dev). Requires π [`jq`](stedolan.github.io/jq/). (Completions / ZSH on Windows)
README
# Nx completion plugin for Zsh
> This plugin bring Nx autocompletion to Zsh.

## Features
- β
**Dynamic command & option parsing**
Automatically discovers and updates completions from `nx --help` output
- π **Intelligent caching = blazing fast completions**
Leverages Nxβs project graph cache and memoized command parsing
- π§ **Workspace-aware, always up-to-date**
Auto-syncs completions with your Nx version, project executors, and custom generators
- π§© **Deep integration with Nx executors**
Extracts and completes custom workspace commands, targets, and options
- β¨ **Smart autocompletion**
Supports arguments, flags, projects, targets, and generatorsβall in context
- π¦ **Version flexibility**
Works seamlessly across different Nx workspace versions
## Install
### Prerequisit
Install [`jq`](https://stedolan.github.io/jq/) dependency:
```shell
apt install jq
```
On MacOS you can install with:
```shell
brew install jq
```
> **Note**: [`jq`](https://stedolan.github.io/jq/) is a lightweight command-line JSON processor used to manipulate the workspace graph.
### As an [Oh My ZSH!](https://github.com/robbyrussell/oh-my-zsh) custom plugin
Clone the repository into the custom plugins directory:
```shell
git clone git@github.com:jscutlery/nx-completion.git ~/.oh-my-zsh/custom/plugins/nx-completion
```
Then load it as a plugin in your `.zshrc`:
```shell
plugins+=(nx-completion)
```
### Manually
Clone this repository somewhere (`~/.nx-completion` for example):
```shell
git clone git@github.com:jscutlery/nx-completion.git ~/.nx-completion
```
Then source it in your `.zshrc`:
```shell
source ~/.nx-completion/nx-completion.plugin.zsh
```
## Cache Management
When reinstalling or updating the nx-completion plugin, you may need to flush the zsh completion cache to ensure you're using the latest version.
### Quick Cache Clear
The simplest way to clear the zsh completion cache:
```shell
# Clear zsh completion cache and rebuild
rm -rf ~/.zcompdump* && autoload -U compinit && compinit -D
```
### Using the Clear Cache Script
Run the included script for automated cache clearing:
```shell
# Make executable and run
chmod +x clear-cache.zsh
./clear-cache.zsh
```
## Testing
This repository includes a comprehensive test environment in the `test/` directory with simplified project structures for easy testing and development.
### Test Environment Structure
```
test/
βββ .nx/workspace-data/project-graph.json # Main test graph (.nodes structure)
βββ nx.json # Nx workspace config
βββ project-graph-nested.json # Test graph (.graph.nodes structure)
βββ test-completion.zsh # Automated test script
βββ test-cache.zsh # Cache performance test script
βββ PERFORMANCE-TESTING.md # Real-world performance testing guide
βββ README.md # Test environment docs
```
### Quick Testing
```bash
# Run automated tests
cd test && ./test-completion.zsh
# Test caching performance
cd test && ./test-cache.zsh
# Interactive completion testing
cd test
source ../nx-completion.plugin.zsh
nx # Test completions
# Performance testing guide
cd test && cat PERFORMANCE-TESTING.md
```
The test environment includes 5 projects (frontend-app, backend-api, shared-utils, ui-components, data-access) with realistic Nx configurations and supports testing both JSON structure formats.
## License
This project is MIT licensed.