File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ func Execute(currentVersion string) error {
3131 info := version .FetchUpdateInfo (rootCmd .Version )
3232 defer info .PromptUpdateIfAvailable ()
3333 ctx := version .WithContext (context .Background (), & info )
34+ patchBashCompletionHelp ()
3435 return rootCmd .ExecuteContext (ctx )
3536}
3637
@@ -194,3 +195,21 @@ func requireAuth(cmd *cobra.Command, args []string) {
194195 err = viper .WriteConfig ()
195196 promptLoginAndExitIf (err != nil )
196197}
198+
199+ // patchBashCompletionHelp adjusts Cobra's generated bash completion help.
200+ //
201+ // Cobra's default Linux example redirects into /etc/bash_completion.d, which
202+ // fails for non-root shells. Use sudo tee so only the file write is elevated.
203+ func patchBashCompletionHelp () {
204+ rootCmd .InitDefaultCompletionCmd ()
205+
206+ bashCmd , _ , err := rootCmd .Find ([]string {"completion" , "bash" })
207+ if err != nil || bashCmd == nil {
208+ return
209+ }
210+
211+ old := "bootdev completion bash > /etc/bash_completion.d/bootdev"
212+ new := "bootdev completion bash | sudo tee /etc/bash_completion.d/bootdev > /dev/null"
213+
214+ bashCmd .Long = strings .Replace (bashCmd .Long , old , new , 1 )
215+ }
You can’t perform that action at this time.
0 commit comments