Skip to content

Commit

Permalink
Autocomplete (#14)
Browse files Browse the repository at this point in the history
* Add bash script snippet for autocompletion

* Update REDAME for how to setup bashcompletion

* Update CHANGELOG

---------

Co-authored-by: zwoefler <>
  • Loading branch information
zwoefler authored Sep 4, 2024
1 parent 558d4cd commit 8237fa1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v0.3.0 - 2024-09-04
FEATURE: Add autocompletion for BASH

- Added: Bash autocompletion output
- Update: README, how to add bashcompletion


## v0.2.2 - 2024-09-04
UPDATE: Simplified README

Expand Down
17 changes: 16 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ compdef _VmChamp_zsh_complete vmchamp
AnsiConsole.WriteLine(zsh);
}
else if (complete == "bash")
{
var bash = """
_vmchamp_bash_complete() {
COMPREPLY=()
local word=${COMP_WORDS[COMP_CWORD]}
local line=${COMP_LINE}
COMPREPLY=($(compgen -W '$(vmchamp '[complete]' "${line}")' -- ${word}))
return 0
}
complete -F _vmchamp_complete vmchamp
""";
AnsiConsole.WriteLine(bash);
}
}, completionOption);

var builder = new CommandLineBuilder(rootCommand).UseDefaults();
Expand All @@ -61,7 +76,7 @@ compdef _VmChamp_zsh_complete vmchamp
var parseResult = app.Parse(args[1]);

var lastToken = parseResult.Tokens.LastOrDefault();

var completions = parseResult.GetCompletions()
.Where(completion => completion.Label is not "-?" and not "-h" and not "/?" and not "/h")
.ToArray();
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ Which leads to output:
user@testvm:~$
```

### Add Shell completion
Add the following to your `.bashrc` or `.zshrc` file
```BASH
# For BASH
source <(vmchamp --completion bash)

# For ZSH
source <(vmchamp --completion zsh)
```


## 🛠️ Installation
TESTED on: `Ubuntu 22.04`; `Debian 12`
Expand Down

0 comments on commit 8237fa1

Please sign in to comment.