2020-04-28 18:53:20 +02:00
|
|
|
package genautocomplete
|
|
|
|
|
|
|
|
import (
|
2024-08-18 16:58:35 +02:00
|
|
|
"fmt"
|
2020-10-10 23:16:21 +02:00
|
|
|
"os"
|
2020-04-28 18:53:20 +02:00
|
|
|
|
|
|
|
"github.com/rclone/rclone/cmd"
|
2024-08-18 16:58:35 +02:00
|
|
|
"github.com/rclone/rclone/fs"
|
2020-04-28 18:53:20 +02:00
|
|
|
"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-12 18:17:46 +02:00
|
|
|
Long: `Generates a fish autocompletion script for rclone.
|
2020-04-28 18:53:20 +02:00
|
|
|
|
|
|
|
This writes to /etc/fish/completions/rclone.fish by default so will
|
2020-10-13 23:49:58 +02:00
|
|
|
probably need to be run with sudo or as root, e.g.
|
2020-04-28 18:53:20 +02:00
|
|
|
|
2024-01-31 17:43:20 +01:00
|
|
|
sudo rclone completion fish
|
2020-04-28 18:53:20 +02: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-10 23:16:21 +02:00
|
|
|
|
|
|
|
If output_file is "-", then the output will be written to stdout.
|
2020-04-28 18:53:20 +02: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-10 23:16:21 +02:00
|
|
|
if args[0] == "-" {
|
|
|
|
err := cmd.Root.GenFishCompletion(os.Stdout, true)
|
|
|
|
if err != nil {
|
2024-08-18 16:58:35 +02:00
|
|
|
fs.Fatal(nil, fmt.Sprint(err))
|
2020-10-10 23:16:21 +02:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2020-04-28 18:53:20 +02:00
|
|
|
out = args[0]
|
|
|
|
}
|
|
|
|
err := cmd.Root.GenFishCompletionFile(out, true)
|
|
|
|
if err != nil {
|
2024-08-18 16:58:35 +02:00
|
|
|
fs.Fatal(nil, fmt.Sprint(err))
|
2020-04-28 18:53:20 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|