Skip to content

Commit

Permalink
feat: Disable custom completions by default
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jan 9, 2022
1 parent 8d348d1 commit b42b3eb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/REFERENCE.md
Expand Up @@ -381,6 +381,7 @@ The following configuration variables are available:
| `bitwarden` | `command` | string | `bw` | Bitwarden CLI command |
| `cd` | `args` | []string | *none* | Extra args to shell in `cd` command |
| | `command` | string | *none* | Shell to run in `cd` command |
| `completion` | `custom` | bool | `false` | Enable custom shell completions |
| `diff` | `args` | []string | *see `diff` below* | Extra args to external diff command |
| | `command` | string | *none* | External diff command |
| | `exclude` | []string | *none* | Entry types to exclude from diffs |
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/completioncmd.go
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/spf13/cobra"
)

type completionCmdConfig struct {
Custom bool `mapstructure:"custom"`
}

func (c *Config) newCompletionCmd() *cobra.Command {
completionCmd := &cobra.Command{
Use: "completion shell",
Expand Down
19 changes: 12 additions & 7 deletions internal/cmd/config.go
Expand Up @@ -122,13 +122,14 @@ type Config struct {
keyring keyringData

// Command configurations, settable in the config file.
Add addCmdConfig `mapstructure:"add"`
CD cdCmdConfig `mapstructure:"cd"`
Diff diffCmdConfig `mapstructure:"diff"`
Docs docsCmdConfig `mapstructure:"docs"`
Edit editCmdConfig `mapstructure:"edit"`
Git gitCmdConfig `mapstructure:"git"`
Merge mergeCmdConfig `mapstructure:"merge"`
Add addCmdConfig `mapstructure:"add"`
CD cdCmdConfig `mapstructure:"cd"`
Completion completionCmdConfig `mapstructure:"completion"`
Diff diffCmdConfig `mapstructure:"diff"`
Docs docsCmdConfig `mapstructure:"docs"`
Edit editCmdConfig `mapstructure:"edit"`
Git gitCmdConfig `mapstructure:"git"`
Merge mergeCmdConfig `mapstructure:"merge"`

// Command configurations, not settable in the config file.
apply applyCmdConfig
Expand Down Expand Up @@ -1954,6 +1955,10 @@ func (c *Config) targetRelPathsBySourcePath(
func (c *Config) targetValidArgs(
cmd *cobra.Command, args []string, toComplete string,
) ([]string, cobra.ShellCompDirective) {
if !c.Completion.Custom {
return nil, cobra.ShellCompDirectiveDefault
}

toCompleteAbsPath, err := chezmoi.NewAbsPathFromExtPath(toComplete, c.homeDirAbsPath)
if err != nil {
cobra.CompErrorln(err.Error())
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/testdata/scripts/completion_unix.txt
Expand Up @@ -44,6 +44,9 @@ $HOME/.file
-- golden/complete-target-home-dot-f --
$HOME/.file
:4
-- home/user/.config/chezmoi/chezmoi.toml --
[completion]
custom = true
-- home/user/.local/share/chezmoi/dot_dir/file --
# contents of .dir/file
-- home/user/.local/share/chezmoi/dot_file --
Expand Down

0 comments on commit b42b3eb

Please sign in to comment.