Skip to content

Commit

Permalink
Merge branch 'main' into fatih/check-for-new-version
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih authored Apr 23, 2021
2 parents 738969d + 26cd655 commit ec8c4e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/cmd/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ second argument:
"-P", port,
}

styledBranch := formatMySQLBranch(database, branch)
m := &mysql{}
err = m.Run(ctx, mysqlArgs...)
err = m.Run(ctx, styledBranch, mysqlArgs...)
return err

},
Expand All @@ -189,6 +190,16 @@ second argument:
return cmd
}

func formatMySQLBranch(database, branch string) string {
branchStyled := printer.BoldBlue(branch)
if branch == "main" {
branchStyled = printer.BoldRed(branch)
}

return printer.Bold(fmt.Sprintf("%s/%s> ", database, branchStyled))

}

// createLoginFile creates a temporary file to store the username and password, so we don't have to
// pass them as `mysql` command-line arguments.
func createLoginFile(username, password string) (string, error) {
Expand All @@ -210,12 +221,15 @@ type mysql struct {
}

// Run runs the `mysql` client with the given arguments.
func (m *mysql) Run(ctx context.Context, args ...string) error {
func (m *mysql) Run(ctx context.Context, styledBranch string, args ...string) error {
c := exec.CommandContext(ctx, "mysql", args...)
if m.Dir != "" {
c.Dir = m.Dir
}

c.Env = append(os.Environ(),
fmt.Sprintf("MYSQL_PS1=%s", styledBranch))

c.Stdout = os.Stdout
c.Stderr = os.Stderr
c.Stdin = os.Stdin
Expand Down
5 changes: 5 additions & 0 deletions internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ func BoldBlue(msg string) string {
return color.New(color.FgBlue).Add(color.Bold).Sprint(msg)
}

// BoldRed returns a string formatted with red and bold.
func BoldRed(msg string) string {
return color.New(color.FgRed).Add(color.Bold).Sprint(msg)
}

// Bold returns a string formatted with bold.
func Bold(msg string) string {
// the 'color' package already handles IsTTY gracefully
Expand Down

0 comments on commit ec8c4e2

Please sign in to comment.