added completion support

This commit is contained in:
2022-10-31 16:19:12 +01:00
parent 6f49b76607
commit 8552270a68
4 changed files with 168 additions and 1 deletions

View File

@@ -54,6 +54,26 @@ func Execute() {
sortmode cfg.Sortmode
)
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
}
},
}
var rootCmd = &cobra.Command{
Use: "tablizer [regex] [file, ...]",
Short: "[Re-]tabularize tabular data",
@@ -81,6 +101,8 @@ func Execute() {
},
}
rootCmd.AddCommand(completionCmd)
// options
rootCmd.PersistentFlags().BoolVarP(&conf.Debug, "debug", "d", false, "Enable debugging")
rootCmd.PersistentFlags().BoolVarP(&conf.NoNumbering, "no-numbering", "n", false, "Disable header numbering")

View File

@@ -199,6 +199,46 @@ DESCRIPTION
<T_COLUMNS> - comma separated list of columns to output, like -c
<NO_COLORS> - disable colorization of matches, like -N
COMPLETION
Bash:
source <(%[1]s completion bash)
To load completions for each session, execute once:
# Linux:
$ tablizer completion bash > /etc/bash_completion.d/%[1]s
# macOS:
$ tablizer completion bash > $(brew --prefix)/etc/bash_completion.d/%[1]s
Zsh:
If shell completion is not already enabled in your environment, you
will need to enable it. You can execute the following once:
echo "autoload -U compinit; compinit" >> ~/.zshrc
To load completions for each session, execute once:
$ tablizer completion zsh > "${fpath[1]}/_%[1]s"
You will need to start a new shell for this setup to take effect.
fish:
tablizer completion fish | source
To load completions for each session, execute once:
tablizer completion fish > ~/.config/fish/completions/%[1]s.fish
PowerShell:
tablizer completion powershell | Out-String | Invoke-Expression
To load completions for every new session, run:
tablizer completion powershell > tablizer.ps1
and source this file from your PowerShell profile.
BUGS
In order to report a bug, unexpected behavior, feature requests or to
submit a patch, please open an issue on github: