Skip to content

Commit

Permalink
rpk: add name by default to the prompt if not empty
Browse files Browse the repository at this point in the history
If a user has a prompt but no "%p" nor "%n" then
we will print the name.
  • Loading branch information
r-vasquez committed Jul 13, 2023
1 parent 1b5a94d commit c8436af
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/go/rpk/pkg/cli/profile/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ func parsePrompt(s string, name string) (string, []color.Attribute, error) {
}

output := make([]byte, 0, len(s)+len(text))
var withEscape bool
for i := 0; i < len(text); i++ {
c := text[i]
switch c {
case '%':
withEscape = true
if len(text) > i+1 {
switch text[i+1] {
case 'p', 'n':
Expand All @@ -209,6 +211,9 @@ func parsePrompt(s string, name string) (string, []color.Attribute, error) {
output = append(output, c)
}
}
if !withEscape {
output = append(output, name...)
}
return string(output), attrs, nil
}

Expand Down

0 comments on commit c8436af

Please sign in to comment.