github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/cmd/genautocomplete/genautocomplete_bash.go (about) 1 package genautocomplete 2 3 import ( 4 "log" 5 6 "github.com/rclone/rclone/cmd" 7 "github.com/spf13/cobra" 8 ) 9 10 func init() { 11 completionDefinition.AddCommand(bashCommandDefinition) 12 } 13 14 var bashCommandDefinition = &cobra.Command{ 15 Use: "bash [output_file]", 16 Short: `Output bash completion script for rclone.`, 17 Long: ` 18 Generates a bash shell autocompletion script for rclone. 19 20 This writes to /etc/bash_completion.d/rclone by default so will 21 probably need to be run with sudo or as root, eg 22 23 sudo rclone genautocomplete bash 24 25 Logout and login again to use the autocompletion scripts, or source 26 them directly 27 28 . /etc/bash_completion 29 30 If you supply a command line argument the script will be written 31 there. 32 `, 33 Run: func(command *cobra.Command, args []string) { 34 cmd.CheckArgs(0, 1, command, args) 35 out := "/etc/bash_completion.d/rclone" 36 if len(args) > 0 { 37 out = args[0] 38 } 39 err := cmd.Root.GenBashCompletionFile(out) 40 if err != nil { 41 log.Fatal(err) 42 } 43 }, 44 }