Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename bgps to git-prompt-string #36

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ jobs:
npm install @semantic-release/git @semantic-release/changelog @semantic-release/exec -D
npx semantic-release
env:
GH_TOKEN: ${{ secrets.BGPS_CI_TOKEN }}
GITHUB_TOKEN: ${{ secrets.BGPS_CI_TOKEN }}
GH_TOKEN: ${{ secrets.GIT_PROMPT_STRING_CI_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GIT_PROMPT_STRING_CI_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ dist/
node_modules/
package-lock.json
package.json
git-prompt-string
git-prompt-string.exe
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
help:
@echo "==> describe make commands"
@echo ""
@echo "build ==> build bgps for current GOOS and GOARCH"
@echo "build ==> build binary for current GOOS and GOARCH"
@echo "test ==> run tests"

.PHONY: build
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Better Git Prompt String
# 📍 git-prompt-string

> [!WARNING]\
> 03/20/2024: bgps is actively undergoing a major v2 rewrite in ![go](https://img.shields.io/badge/Go-00ADD8?style=flat-square&logo=go&logoColor=white)
> 03/20/2024: git-prompt-string (previously bgps) is actively undergoing a major v2 rewrite in ![go](https://img.shields.io/badge/Go-00ADD8?style=flat-square&logo=go&logoColor=white)
>
> This is a breaking change that will simplify and improve maintainability of bgps
> This is a breaking change that will simplify and improve maintainability of git-prompt-string
>
> If you prefer to keep using legacy bgps, then use the tag [v1.0.0](https://github.com/mikesmithgh/bgps/releases/tag/v1.0.0)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/mikesmithgh/bgps
module github.com/mikesmithgh/git-prompt-string

go 1.22.0

Expand Down
12 changes: 6 additions & 6 deletions integration/bgps_test.go → integration/gps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
)

func TestBGPS(t *testing.T) {
func TestGPS(t *testing.T) {
var notFoundMsg string
if runtime.GOOS == "windows" {
notFoundMsg = "The system cannot find the path specified."
Expand Down Expand Up @@ -72,13 +72,13 @@ func TestBGPS(t *testing.T) {
{"dirty", []string{"--config=../configs/color_overrides.toml"}, "\x1b[48;2;179;5;89m \ue0a0 main *\x1b[0m", nil},
{"conflict_ahead", []string{"--config=../configs/color_overrides.toml"}, "\x1b[38;2;252;183;40m \ue0a0 main ↑[1]\x1b[0m", nil},
{"untracked", []string{"--config=../configs/color_overrides.toml"}, "\x1b[38;2;255;0;0m\x1b[48;2;22;242;170m \ue0a0 main *\x1b[0m", nil},
{"bisect", []string{}, "\x1b[48;2;204;204;255m\x1b[35m \ue0a0 main|BISECTING ↓[1]\x1b[0m", []string{"BGPS_CONFIG=../configs/color_overrides.toml"}},
{"bisect", []string{}, "\x1b[48;2;204;204;255m\x1b[35m \ue0a0 main|BISECTING ↓[1]\x1b[0m", []string{"GIT_PROMPT_STRING_CONFIG=../configs/color_overrides.toml"}},

// config errors
{"clean", []string{"--config=/fromparam/does/not/exist"}, fmt.Sprintf("\x1b[31m bgps error(read config): open /fromparam/does/not/exist: %s\x1b[0m", notFoundMsg), nil},
{"configs", []string{}, fmt.Sprintf("\x1b[31m bgps error(read config): open /fromenvvar/does/not/exist: %s\x1b[0m", notFoundMsg), []string{"BGPS_CONFIG=/fromenvvar/does/not/exist"}},
{"configs", []string{"--config=invalid_syntax.toml"}, "\x1b[31m bgps error(unmarshal config): toml: expected character =\x1b[0m", nil},
{"configs", []string{}, "\x1b[31m bgps error(unmarshal config): toml: expected character =\x1b[0m", []string{"BGPS_CONFIG=invalid_syntax.toml"}},
{"clean", []string{"--config=/fromparam/does/not/exist"}, fmt.Sprintf("\x1b[31m git-prompt-string error(read config): open /fromparam/does/not/exist: %s\x1b[0m", notFoundMsg), nil},
{"configs", []string{}, fmt.Sprintf("\x1b[31m git-prompt-string error(read config): open /fromenvvar/does/not/exist: %s\x1b[0m", notFoundMsg), []string{"GIT_PROMPT_STRING_CONFIG=/fromenvvar/does/not/exist"}},
{"configs", []string{"--config=invalid_syntax.toml"}, "\x1b[31m git-prompt-string error(unmarshal config): toml: expected character =\x1b[0m", nil},
{"configs", []string{}, "\x1b[31m git-prompt-string error(unmarshal config): toml: expected character =\x1b[0m", []string{"GIT_PROMPT_STRING_CONFIG=invalid_syntax.toml"}},

{"norepo", []string{"--config=NONE"}, "", nil},
}
Expand Down
8 changes: 4 additions & 4 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ func TestMain(m *testing.M) {
}
defer os.RemoveAll(tmpDir)

bgps := "bgps"
gps := "git-prompt-string"
if runtime.GOOS == "windows" {
bgps += ".exe"
gps += ".exe"
}
builtBinaryPath = filepath.Join(tmpDir, bgps)
builtBinaryPath = filepath.Join(tmpDir, gps)

cmd := exec.Command("go", "build", "-o", builtBinaryPath, "..")
output, err := cmd.CombinedOutput()
if err != nil {
panic(fmt.Sprintf("failed to build bgps: %s, %s", output, err))
panic(fmt.Sprintf("failed to build gps: %s, %s", output, err))
}

cmd = exec.Command("cp", "-r", "../testdata", tmpDir)
Expand Down
30 changes: 15 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"runtime"
"strings"

"github.com/mikesmithgh/bgps/pkg/color"
"github.com/mikesmithgh/bgps/pkg/config"
"github.com/mikesmithgh/bgps/pkg/git"
"github.com/mikesmithgh/bgps/pkg/util"
"github.com/mikesmithgh/git-prompt-string/pkg/color"
"github.com/mikesmithgh/git-prompt-string/pkg/config"
"github.com/mikesmithgh/git-prompt-string/pkg/git"
"github.com/mikesmithgh/git-prompt-string/pkg/util"
"github.com/pelletier/go-toml/v2"
)

Expand All @@ -33,7 +33,7 @@ var (
)

func main() {
cfg := config.BgpsConfig{
cfg := config.GPSConfig{
PromptPrefix: *promptPrefix,
PromptSuffix: *promptSuffix,
AheadFormat: *aheadFormat,
Expand All @@ -51,14 +51,14 @@ func main() {

flag.Parse()

var bgpsConfigPath string
bgpsConfigEnv := os.Getenv("BGPS_CONFIG")
var gpsConfig string
gpsConfigEnv := os.Getenv("GIT_PROMPT_STRING_CONFIG")
if *configPath == "" {
bgpsConfigPath = bgpsConfigEnv
gpsConfig = gpsConfigEnv
} else {
bgpsConfigPath = *configPath
gpsConfig = *configPath
}
if bgpsConfigPath == "" {
if gpsConfig == "" {
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
if xdgConfigHome == "" {
home, err := os.UserHomeDir()
Expand All @@ -71,20 +71,20 @@ func main() {
xdgConfigHome = path.Join(home, ".config")
}
}
bgpsConfigPath = path.Join(xdgConfigHome, "bgps", "config.toml")
gpsConfig = path.Join(xdgConfigHome, "git-prompt-string", "config.toml")
}

if bgpsConfigPath != "NONE" {
bgpsConfigRaw, err := os.ReadFile(bgpsConfigPath)
if gpsConfig != "NONE" {
gpsConfigRaw, err := os.ReadFile(gpsConfig)
if err != nil && !os.IsNotExist(err) {
util.ErrMsg("read config exists", err, 0)
}

if err != nil && (*configPath != "" || bgpsConfigEnv != "") {
if err != nil && (*configPath != "" || gpsConfigEnv != "") {
util.ErrMsg("read config", err, 0)
}

err = toml.Unmarshal(bgpsConfigRaw, &cfg)
err = toml.Unmarshal(gpsConfigRaw, &cfg)
if err != nil {
util.ErrMsg("unmarshal config", err, 0)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package config

type BgpsConfig struct {
type GPSConfig struct {
PromptPrefix string `toml:"prompt_prefix"`
PromptSuffix string `toml:"prompt_suffix"`
AheadFormat string `toml:"ahead_format"`
Expand Down
10 changes: 5 additions & 5 deletions pkg/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"path/filepath"
"strings"

"github.com/mikesmithgh/bgps/pkg/color"
"github.com/mikesmithgh/bgps/pkg/config"
"github.com/mikesmithgh/bgps/pkg/util"
"github.com/mikesmithgh/git-prompt-string/pkg/color"
"github.com/mikesmithgh/git-prompt-string/pkg/config"
"github.com/mikesmithgh/git-prompt-string/pkg/util"
)

type GitRepo struct {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (g *GitRepo) ReadGitDirFileExitOnError(name string) string {
return content
}

func (g *GitRepo) BranchInfo(cfg config.BgpsConfig) (string, error) {
func (g *GitRepo) BranchInfo(cfg config.GPSConfig) (string, error) {
var err error
ref := ""
step := ""
Expand Down Expand Up @@ -190,7 +190,7 @@ func (g *GitRepo) BranchInfo(cfg config.BgpsConfig) (string, error) {
return prompt, nil
}

func (g *GitRepo) BranchStatus(cfg config.BgpsConfig) (string, string, error) {
func (g *GitRepo) BranchStatus(cfg config.GPSConfig) (string, string, error) {
status := ""
statusColor := ""

Expand Down
4 changes: 2 additions & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"strings"

"github.com/mikesmithgh/bgps/pkg/color"
"github.com/mikesmithgh/git-prompt-string/pkg/color"
)

func IsDir(name string) bool {
Expand Down Expand Up @@ -42,6 +42,6 @@ func ErrMsg(hint string, e error, exitCode int) {
} else {
error_msg = strings.ReplaceAll(strings.ReplaceAll(e.Error(), "\n", ""), "\r", "")
}
fmt.Printf("%s bgps error(%s): %s%s", errorColor, hint, error_msg, clearColor)
fmt.Printf("%s git-prompt-string error(%s): %s%s", errorColor, hint, error_msg, clearColor)
os.Exit(exitCode)
}