Skip to content

Commit

Permalink
Update completion documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kardolus committed Feb 23, 2024
1 parent 3e25940 commit 5cb02c8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 455 deletions.
52 changes: 37 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Azure, featuring streaming capabilities and extensive configuration options.
- [General Configuration](#general-configuration)
- [Azure Configuration](#azure-configuration)
- [Command-Line Autocompletion](#command-line-autocompletion)
- [Enabling Autocompletion](#enabling-autocompletion)
- [Persistent Autocompletion](#persistent-autocompletion)
- [Development](#development)
- [Reporting Issues and Contributing](#reporting-issues-and-contributing)
- [Uninstallation](#uninstallation)
Expand Down Expand Up @@ -266,29 +268,49 @@ You can set the API key either in the `config.yaml` file as shown above or expor
export AZURE_API_KEY=<your_key>
```

### Command-Line Autocompletion.
### Command-Line Autocompletion

We've introduced a new feature to enhance your CLI experience: a completion script for flag completion! This script
allows you to use tab completion for command flags, making it easier and faster to use the ChatGPT CLI.
Enhance your CLI experience with our new autocompletion feature for command flags!

To enable this feature, simply source the completion script from your terminal:
#### Enabling Autocompletion

```bash
source scripts/completion.sh
```
Autocompletion is currently supported for the following shells: Bash, Zsh, Fish, and PowerShell. To activate flag
completion in your current shell session, execute the appropriate command based on your shell:

This command adds flag completion to your current shell session. For convenience, you can add the sourcing command to
your shell's startup file (e.g., `.bashrc`, `.zshrc`) to automatically enable flag completion every time you open a new
terminal window:
- **Bash**
```bash
. <(chatgpt --set-completions bash)
```
- **Zsh**
```zsh
. <(chatgpt --set-completions zsh)
```
- **Fish**
```fish
chatgpt --set-completions fish | source
```
- **PowerShell**
```powershell
chatgpt --set-completions powershell | Out-String | Invoke-Expression
```

#### Persistent Autocompletion

For added convenience, you can make autocompletion persist across all new shell sessions by adding the appropriate
sourcing command to your shell's startup file. Here are the files typically used for each shell:
- **Bash**: Add to `.bashrc` or `.bash_profile`
- **Zsh**: Add to `.zshrc`
- **Fish**: Add to `config.fish`
- **PowerShell**: Add to your PowerShell profile script
For example, for Bash, you would add the following line to your `.bashrc` file:
```bash
echo "source $(pwd)/scripts/completion.sh" >> ~/.bashrc
. <(chatgpt --set-completions bash)
```
*Note: Replace `~/.bashrc` with the appropriate startup file for your shell, such as `~/.zshrc` for Zsh users.*

By sourcing `completion.sh`, you'll enjoy a more streamlined and efficient workflow with the ChatGPT CLI, with quick
access to available flags and options right at your fingertips.
This ensures that command flag autocompletion is enabled automatically every time you open a new terminal window.
## Development
Expand Down
2 changes: 1 addition & 1 deletion cmd/chatgpt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
rootCmd.PersistentFlags().BoolVarP(&listThreads, "list-threads", "", false, "List available threads")
rootCmd.PersistentFlags().StringVar(&modelName, "set-model", "", "Set a new default GPT model by specifying the model name")
rootCmd.PersistentFlags().StringVar(&threadName, "set-thread", "", "Set a new active thread by specifying the thread name")
rootCmd.PersistentFlags().StringVar(&shell, "set-completions", "", "Generate autocompletion script for your current SHELL")
rootCmd.PersistentFlags().StringVar(&shell, "set-completions", "", "Generate autocompletion script for your current shell")

rootCmd.PersistentFlags().IntVar(&maxTokens, "set-max-tokens", 0, "Set a new default max token size by specifying the max tokens")

Expand Down
Loading

0 comments on commit 5cb02c8

Please sign in to comment.