Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ My one slight annoyance is the manual set up required for a new host/account whi
### Bash

```bash
complete -F _git roam
eval "$(roam completion bash)"
```

Maybe somehow also use,
Expand Down
13 changes: 12 additions & 1 deletion completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ func (a *app) completionCommand() *cobra.Command {
}
var force bool
out := a.defaultZshOut()
bash := &cobra.Command{
Use: "bash",
Short: "Generate the autocompletion script for bash",
Args: cobra.NoArgs,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, _ []string) error {
_, err := fmt.Fprintln(cmd.OutOrStdout(), "complete -F _git roam")
return err
},
}
zsh := &cobra.Command{
Use: "zsh",
Short: "Generate the autocompletion script for zsh",
Expand All @@ -58,7 +69,7 @@ func (a *app) completionCommand() *cobra.Command {
}
zsh.Flags().BoolVarP(&force, "force", "f", false, "Overwrite existing generated files")
zsh.Flags().StringVarP(&out, "out", "o", out, "Output directory for generated files (~/.local/share/zsh/site-functions)")
cmd.AddCommand(zsh)
cmd.AddCommand(bash, zsh)
return cmd
}

Expand Down
12 changes: 11 additions & 1 deletion completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import (
"github.com/stretchr/testify/require"
)

func TestCompletionBash(t *testing.T) {
app, _ := testApp(t)
var stdout bytes.Buffer
app.stdout = &stdout
require.NoError(t, app.run(t.Context(), []string{"completion", "bash"}))
require.Equal(t, "complete -F _git roam\n", stdout.String())
}

func TestCompletionZsh(t *testing.T) {
app, _ := testApp(t)
out := filepath.Join(app.home, "completions")
Expand Down Expand Up @@ -67,7 +75,9 @@ func TestCompletionHelp(t *testing.T) {
var stdout bytes.Buffer
app.stdout = &stdout
require.NoError(t, app.run(t.Context(), []string{"completion", "-h"}))
require.Contains(t, stdout.String(), "zsh")
help := stdout.String()
require.Contains(t, help, "bash")
require.Contains(t, help, "zsh")
}

func TestCompletionZshTildeOut(t *testing.T) {
Expand Down
Loading