Skip to content

Commit

Permalink
Fully support uv completion, if installed
Browse files Browse the repository at this point in the history
  • Loading branch information
AndydeCleyre committed Apr 20, 2024
1 parent 89a441a commit 11afeb6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Unreleased
Changed
-------

- Use uv completion rather than pip or pip-compile completion
when uv is installed, affecting:
``pipc``, ``pipcs``, ``pipacs``, ``pipac``, and ``pipi``
- Document installation of uv completion
- Restore ``highlight`` to top detected syntax highlighter,
after confirming Linux Mint renamed their ``highlight`` to ``highlight-mint``
- Re-add ``highlight`` to the demo images
Expand Down
1 change: 1 addition & 0 deletions doc/mkdocs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ nav:
- help_all.md
- deps.md
- install.md
- completions.md
36 changes: 36 additions & 0 deletions doc/src/completions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Completions

If you've been using Zsh, you probably have completions already set up,
either manually or with a framework.

If not, at a minimum you'll want this in your `~/.zshrc`,
somewhere before loading zpy:

```shell
autoload -Uz compinit && compinit
```

Some functions allow you to pass arguments through to other tools,
like `pip`, `pip-compile`, and `uv`.
Completion will work for those if you install their own completion definitions.

If using `uv`, neither `pip` nor `pip-compile` will be relevant.

``uv`` completion can be installed with something like the following,
depending on your `$fpath`:

```console
% uv generate-shell-completion zsh >~/.local/share/zsh/site-functions/_uv
```

You can check for appropriate folders with:

```console
% print -rl -- $fpath
```

Filter to .../username/... paths for the most likely candidates:

```console
% print -rl -- ${(M)fpath:#*/$USER/*}
```
36 changes: 28 additions & 8 deletions zpy.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2427,8 +2427,13 @@ _.zpy_ui_pipc () {
local i=$words[(i)--]
if (( CURRENT > $i )) {
shift i words
words=(pip-compile $words)
(( CURRENT-=i, CURRENT+=1 ))
if (( $+commands[uv] )) {
words=(uv pip compile $words)
(( CURRENT-=i, CURRENT+=3 ))
} else {
words=(pip-compile $words)
(( CURRENT-=i, CURRENT+=1 ))
}
_normal -P
return
}
Expand All @@ -2455,8 +2460,13 @@ _.zpy_ui_pipcs () {
local i=$words[(i)--]
if (( CURRENT > $i )) {
shift i words
words=(pip-compile $words)
(( CURRENT-=i, CURRENT+=1 ))
if (( $+commands[uv] )) {
words=(uv pip compile $words)
(( CURRENT-=i, CURRENT+=3 ))
} else {
words=(pip-compile $words)
(( CURRENT-=i, CURRENT+=1 ))
}
_normal -P
return
}
Expand Down Expand Up @@ -2497,8 +2507,13 @@ _.zpy_ui_pipi () {
"(--help)--no-upgrade[Don't upgrade already-installed packages]" \
"(-)*:::Option or Package Spec:->opt_or_pkgspec"
if [[ $state == opt_or_pkgspec ]] {
words=(pip install $words)
(( CURRENT+=2 ))
if (( $+commands[uv] )) {
words=(uv pip install $words)
(( CURRENT+=3 ))
} else {
words=(pip install $words)
(( CURRENT+=2 ))
}
_normal
_zpy_pypi_pkg --or-local
# TODO: Still quite sloppy... though so is upstream pip completion
Expand Down Expand Up @@ -2572,8 +2587,13 @@ _.zpy_ui_reqshow () {
local i=$words[(i)--]
if (( CURRENT > $i )) {
shift i words
words=(pip-compile $words)
(( CURRENT-=i, CURRENT+=1 ))
if (( $+commands[uv] )) {
words=(uv pip compile $words)
(( CURRENT-=i, CURRENT+=3 ))
} else {
words=(pip-compile $words)
(( CURRENT-=i, CURRENT+=1 ))
}
_normal -P
return
}
Expand Down

0 comments on commit 11afeb6

Please sign in to comment.