@@ -41,40 +41,27 @@ func makeBashCompletionFileIfNeeded(cmd *cobra.Command) {
41
41
return
42
42
}
43
43
44
- if ! file .IsFile (path ) {
45
- fp , err := os .OpenFile (path , os .O_RDWR | os .O_CREATE , 0664 )
46
- if err != nil {
47
- print .Err (fmt .Errorf ("can not open .bash_completion: %w" , err ))
48
- return
49
- }
50
-
51
- if _ , err := fp .WriteString (bashCompletion .String ()); err != nil {
52
- print .Err (fmt .Errorf ("can not write .bash_completion %w" , err ))
53
- return
54
- }
55
-
56
- if err := fp .Close (); err != nil {
57
- print .Err (fmt .Errorf ("can not close .bash_completion %w" , err ))
44
+ if ! file .IsDir (path ) {
45
+ if err := os .MkdirAll (filepath .Dir (path ), 0775 ); err != nil {
46
+ print .Err (fmt .Errorf ("can not create bash-completion file: %w" , err ))
58
47
return
59
48
}
60
- return
61
49
}
62
-
63
- fp , err := os .OpenFile (path , os .O_RDWR | os .O_APPEND , 0664 )
50
+ fp , err := os .OpenFile (path , os .O_RDWR | os .O_CREATE , 0664 )
64
51
if err != nil {
65
52
print .Err (fmt .Errorf ("can not open .bash_completion: %w" , err ))
66
53
return
67
54
}
68
55
69
56
if _ , err := fp .WriteString (bashCompletion .String ()); err != nil {
70
- print .Err (fmt .Errorf ("can not append .bash_completion: %w" , err ))
57
+ print .Err (fmt .Errorf ("can not write .bash_completion %w" , err ))
71
58
return
72
59
}
73
60
74
61
if err := fp .Close (); err != nil {
75
- print .Err (fmt .Errorf ("can not close .bash_completion: %w" , err ))
76
- return
62
+ print .Err (fmt .Errorf ("can not close .bash_completion %w" , err ))
77
63
}
64
+ return
78
65
}
79
66
80
67
func makeFishCompletionFileIfNeeded (cmd * cobra.Command ) {
@@ -235,7 +222,7 @@ func isSameZshCompletionFile(cmd *cobra.Command) bool {
235
222
236
223
// bashCompletionFilePath return bash-completion file path.
237
224
func bashCompletionFilePath () string {
238
- return filepath .Join (os .Getenv ("HOME" ), ".bash_completion" )
225
+ return filepath .Join (os .Getenv ("HOME" ), ".bash_completions.d" , cmdinfo . Name )
239
226
}
240
227
241
228
// fishCompletionFilePath return fish-completion file path.
0 commit comments