Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions .github/workflows/release-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:

- name: Prepare release directory
run: |
mkdir out out/docs
mkdir out out/docs out/complete
cp $BIN out
cp README.md docs/*.md out/docs

Expand All @@ -142,10 +142,48 @@ jobs:
"${{ matrix.qemu }}" "/$BIN" \
--generate man > "out/docs/lychee.1"

- name: Generate shell completions without emulation
if: matrix.qemu == ''
run: |
$BIN --generate complete-bash > out/complete/lychee.bash
$BIN --generate complete-elvish > out/complete/lychee.elv
$BIN --generate complete-fish > out/complete/lychee.fish
$BIN --generate complete-powershell > out/complete/_lychee.ps1
$BIN --generate complete-zsh > out/complete/_lychee

- name: Generate shell completions with emulation
if: matrix.qemu != ''
run: |
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN" \
--generate complete-bash > "out/complete/lychee.bash"
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN" \
--generate complete-elvish > "out/complete/lychee.elv"
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN" \
--generate complete-fish > "out/complete/lychee.fish"
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN" \
--generate complete-powershell > "out/complete/_lychee.ps1"
docker run --rm -v \
"$PWD/target:/target:Z" \
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
"${{ matrix.qemu }}" "/$BIN" \
--generate complete-zsh > "out/complete/_lychee"

- name: Package release
run: |
cd out
tar -czf lychee.tar.gz lychee docs/
tar -czf lychee.tar.gz lychee docs/ complete/

- name: Check if possible to release
if: ${{ needs.prepare.outputs.upload_url == '' }}
Expand Down Expand Up @@ -185,10 +223,15 @@ jobs:
cd target/release
strip lychee
chmod +x lychee
mkdir docs
mkdir docs complete
cp ../../README.md ../../docs/TROUBLESHOOTING.md docs
./lychee --generate man > docs/lychee.1
tar -czf lychee.tar.gz lychee docs/
./lychee --generate complete-bash > complete/lychee.bash
./lychee --generate complete-elvish > complete/lychee.elv
./lychee --generate complete-fish > complete/lychee.fish
./lychee --generate complete-powershell > complete/_lychee.ps1
./lychee --generate complete-zsh > complete/_lychee
tar -czf lychee.tar.gz lychee docs/ complete/

mkdir dmg
mv lychee dmg/
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/test-completions.yml
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a test file to see if the workflow passes and generates those completion files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we remove this workflow before merging, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes yes

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test Completions Generation
on:
workflow_dispatch:
push:
branches:
- add-shell-completions

jobs:
test-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable

- name: Build binary
run: cargo build --release --features vendored-openssl

- name: Test completion generation
run: |
BIN="target/release/lychee"
chmod +x $BIN

# Test all completion types
echo "Testing Bash completion..."
$BIN --generate complete-bash > /tmp/lychee.bash

echo "Testing Elvish completion..."
$BIN --generate complete-elvish > /tmp/lychee.elv

echo "Testing Fish completion..."
$BIN --generate complete-fish > /tmp/lychee.fish

echo "Testing PowerShell completion..."
$BIN --generate complete-powershell > /tmp/_lychee.ps1

echo "Testing Zsh completion..."
$BIN --generate complete-zsh > /tmp/_lychee

# Verify files were created and are not empty
for file in /tmp/lychee.bash /tmp/lychee.elv /tmp/lychee.fish /tmp/_lychee.ps1 /tmp/_lychee; do
if [ ! -s "$file" ]; then
echo "Error: $file is empty or missing"
exit 1
fi
echo "✓ $(basename $file): $(wc -l < $file) lines"
done

echo "✅ All completions generated successfully!"

test-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable

- name: Build and test completions
run: |
cargo build --release
BIN="target/release/lychee"

# Quick test
$BIN --generate complete-bash > /tmp/test.bash
$BIN --generate complete-fish > /tmp/test.fish
$BIN --generate complete-zsh > /tmp/test.zsh

echo "✅ macOS completions work!"
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ Options:
--generate <GENERATE>
Generate special output (e.g. the man page) instead of performing link checking

[possible values: man]
[possible values: man, complete-bash, complete-elvish, complete-fish, complete-powershell, complete-zsh]

--github-token <GITHUB_TOKEN>
GitHub API token to use when checking github.com links, to avoid rate limiting
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc-valid-idents = ["PowerShell", ".."]
1 change: 1 addition & 0 deletions lychee-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ lychee-lib = { path = "../lychee-lib", version = "0.22.0", default-features = fa
anyhow = "1.0.100"
assert-json-diff = "2.0.2"
clap = { version = "4.5.53", features = ["env", "derive", "cargo", "string"] }
clap_complete = "4.5.38"
clap_mangen = "0.2.31"
console = "0.16.2"
const_format = "0.2.35"
Expand Down
150 changes: 150 additions & 0 deletions lychee-bin/complete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Shell Completions for lychee

This directory contains shell completion scripts for lychee.
It unlocks tab-completion for commands, options, and arguments in your shell!

## Quick Reference

Generate completions for your shell:

```bash
lychee --generate complete-bash # Bash
lychee --generate complete-elvish # Elvish
lychee --generate complete-fish # Fish
lychee --generate complete-powershell # PowerShell
lychee --generate complete-zsh # Zsh
```

## Installation

### Bash

**User installation:**
```bash
dir="${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
mkdir -p "$dir"
lychee --generate complete-bash > "$dir/lychee.bash"
```

Then source it in your `~/.bashrc` or `~/.bash_profile`:
```bash
source "$dir/lychee.bash"
```

**System-wide installation:**
```bash
# On Linux
sudo lychee --generate complete-bash > /usr/share/bash-completion/completions/lychee

# On macOS with Homebrew
lychee --generate complete-bash > $(brew --prefix)/etc/bash_completion.d/lychee
```

### Zsh

**Recommended approach:**

```zsh
dir="$HOME/.zsh-completions"
mkdir -p "$dir"
lychee --generate complete-zsh > "$dir/_lychee"
```

Add to your `~/.zshrc`:
```zsh
fpath=($HOME/.zsh-completions $fpath)
autoload -Uz compinit && compinit
```

**System-wide installation:**
```bash
# On Linux
sudo lychee --generate complete-zsh > /usr/local/share/zsh/site-functions/_lychee

# On macOS with Homebrew
lychee --generate complete-zsh > $(brew --prefix)/share/zsh/site-functions/_lychee
```

**Alternative (slower, not recommended for daily use):**

You can generate completions on-the-fly by adding this to `~/.zshrc`:
```zsh
source <(lychee --generate complete-zsh)
```

Note: This is easier to set up but slower, adding startup time to your shell.

### Fish

**User installation:**
```bash
dir="${XDG_CONFIG_HOME:-$HOME/.config}/fish/completions"
mkdir -p "$dir"
lychee --generate complete-fish > "$dir/lychee.fish"
```

Fish will automatically load the completions on next shell start.

**System-wide installation:**
```bash
# On Linux
sudo lychee --generate complete-fish > /usr/share/fish/vendor_completions.d/lychee.fish

# On macOS with Homebrew
lychee --generate complete-fish > $(brew --prefix)/share/fish/vendor_completions.d/lychee.fish
```

### Elvish

```bash
dir="${XDG_CONFIG_HOME:-$HOME/.config}/elvish/lib"
mkdir -p "$dir"
lychee --generate complete-elvish > "$dir/lychee.elv"
```

Then add the following to your `~/.elvish/rc.elv`:
```elvish
use lychee
```

**PowerShell:** Verify your execution policy allows running scripts:
```powershell
Get-ExecutionPolicy
# If restricted, run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```

### Updating completions

After upgrading lychee, regenerate completions to get the latest options:
```bash
lychee --generate complete-<your-shell> > <completion-file>
```

### PowerShell

**Windows:**

Generate the completion file:
```powershell
lychee --generate complete-powershell | Out-File -Encoding UTF8 _lychee.ps1
```

Then add to your PowerShell profile:
```powershell
# Find your profile location
echo $PROFILE

# Add this line to your profile
. C:\Path\To\_lychee.ps1
```

**Linux/macOS with PowerShell:**
```bash
lychee --generate complete-powershell > ~/.config/powershell/_lychee.ps1
```

Add to your profile (`~/.config/powershell/Microsoft.PowerShell_profile.ps1`):
```powershell
. ~/.config/powershell/_lychee.ps1
```
Loading
Loading