Skip to content

Commit

Permalink
Adding documentation for autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
jossmoff committed Oct 24, 2023
1 parent 44fdc7f commit 7d27b78
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineConfig({
items: [
// Each item here is one entry in the navigation menu.
{ label: 'Installation', link: '/getting-started/installation/' },
{ label: 'Enabling Autocomplete', link: '/getting-started/autocomplete/' },
{ label: 'Glossary', link: '/getting-started/glossary/' },
],
},
Expand Down
70 changes: 70 additions & 0 deletions docs/src/content/docs/getting-started/autocomplete.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: Enabling Autocomplete
description: A guide to setting up autocomplete with bookshelf
---
import { Tabs, TabItem } from '@astrojs/starlight/components';


All of this information is taken from the [click documentation](https://click.palletsprojects.com/en/8.1.x/shell-completion/), and you should read it if you want to know more.
In order for completion to be used, the user needs to register a special function with their shell.
The script is different for every shell, and Click will output it for bookshelf when called with `_BOOKSHELF_COMPLETE` set to `{shell}_source`.
The built-in shells are bash, zsh, and fish.

## Using Eval

<Tabs>
<TabItem label="Bash">
Add this to ~/.bashrc:
```bash
eval "$(_BOOKSHELF_COMPLETE=bash_source bookshelf)"
```
</TabItem>
<TabItem label="Zsh">
Add this to ~/.zshrc:
```bash
eval "$(_BOOKSHELF_COMPLETE=zsh_source bookshelf)"
```

</TabItem>
<TabItem label="Fish">
Add this to ~/.config/fish/completions/bookshelf.fish:
```bash
_BOOKSHELF_COMPLETE=fish_source bookshelf | source
```
This is the same file used for the activation script method below. For Fish it’s probably always easier to use that method.
</TabItem>
</Tabs>

## Using an Activation Script
Using eval means that the command is invoked and evaluated every time a shell is started, which can delay shell responsiveness.
To speed it up, write the generated script to a file, then source that.
You can generate the files ahead of time and distribute them with your program to save your users a step.

<Tabs>
<TabItem label="Bash">
Save the script somewhere.
```bash
_BOOKSHELF_COMPLETE=bash_source bookshelf > ~/.bookshelf-complete.bash
```
Source the file in ~/.bashrc.
```bash
. ~/.bookshelf-complete.bash
```
</TabItem>
<TabItem label="Zsh">
Save the script somewhere.
```bash
_BOOKSHELF_COMPLETE=zsh_source bookshelf > ~/.bookshelf-complete.zsh
```
Source the file in ~/.zshrc.
```bash
. ~/.bookshelf-complete.zsh
```
</TabItem>
<TabItem label="Fish">
Save the script to ~/.config/fish/completions/bookshelf.fish:
```bash
_BOOKSHELF_COMPLETE=fish_source bookshelf > ~/.config/fish/completions/bookshelf.fish
```
</TabItem>
</Tabs>
1 change: 0 additions & 1 deletion docs/src/content/docs/getting-started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ description: A guide to install bookshelf
---
import { Tabs, TabItem } from '@astrojs/starlight/components';

## Prerequisites

## Using a Package Manager
You can easily add this project to your own by using your favorite project manager. Here are some examples for popular build tools:
Expand Down

0 comments on commit 7d27b78

Please sign in to comment.