Skip to content

Commit e7df8d1

Browse files
committed
fix bash completion install command
1 parent 677e47c commit e7df8d1

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

cmd/root.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)