2020-04-29 00:53:20 +08:00
|
|
|
package genautocomplete
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2020-10-11 05:16:21 +08:00
|
|
|
"os"
|
2020-04-29 00:53:20 +08:00
|
|
|
|
|
|
|
"github.com/rclone/rclone/cmd"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
completionDefinition.AddCommand(fishCommandDefinition)
|
|
|
|
}
|
|
|
|
|
|
|
|
var fishCommandDefinition = &cobra.Command{
|
|
|
|
Use: "fish [output_file]",
|
|
|
|
Short: `Output fish completion script for rclone.`,
|
2024-08-13 00:17:46 +08:00
|
|
|
Long: `Generates a fish autocompletion script for rclone.
|
2020-04-29 00:53:20 +08:00
|
|
|
|
|
|
|
This writes to /etc/fish/completions/rclone.fish by default so will
|
2020-10-14 05:49:58 +08:00
|
|
|
probably need to be run with sudo or as root, e.g.
|
2020-04-29 00:53:20 +08:00
|
|
|
|
2024-02-01 00:43:20 +08:00
|
|
|
sudo rclone completion fish
|
2020-04-29 00:53:20 +08:00
|
|
|
|
|
|
|
Logout and login again to use the autocompletion scripts, or source
|
|
|
|
them directly
|
|
|
|
|
|
|
|
. /etc/fish/completions/rclone.fish
|
|
|
|
|
|
|
|
If you supply a command line argument the script will be written
|
|
|
|
there.
|
2020-10-11 05:16:21 +08:00
|
|
|
|
|
|
|
If output_file is "-", then the output will be written to stdout.
|
2020-04-29 00:53:20 +08:00
|
|
|
`,
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(0, 1, command, args)
|
|
|
|
out := "/etc/fish/completions/rclone.fish"
|
|
|
|
if len(args) > 0 {
|
2020-10-11 05:16:21 +08:00
|
|
|
if args[0] == "-" {
|
|
|
|
err := cmd.Root.GenFishCompletion(os.Stdout, true)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2020-04-29 00:53:20 +08:00
|
|
|
out = args[0]
|
|
|
|
}
|
|
|
|
err := cmd.Root.GenFishCompletionFile(out, true)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|