From 5e806dc566bfc336c59e2d2f5b353a84d615b753 Mon Sep 17 00:00:00 2001 From: x-stp Date: Fri, 2 May 2025 16:32:14 +0200 Subject: [PATCH 1/2] feat: add fish shell support and upgrade to Go 1.24.2 - Add support for fish shell configuration and path management - Update version to v0.0.10 - Upgrade Go version to 1.24.2 in workflows and documentation - Closes #112 + (squash) rebase commit -> chore(rebased onto dev): commit squashed to omit linter workflow as that doesnt exist in dev no more --- .github/workflows/build-test.yml | 2 +- .github/workflows/lint-test.yml | 26 --------------- .github/workflows/release-binary.yml | 2 +- .github/workflows/release-test.yml | 2 +- .github/workflows/setup-test.yaml | 2 +- README.md | 2 +- internal/runner/banner.go | 2 +- pkg/path/unix.go | 48 +++++++++++++++++++++++++--- 8 files changed, 49 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/lint-test.yml diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 09ead44..5cc2f04 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.21.x + go-version: 1.24.x - name: Check out code uses: actions/checkout@v3 diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml deleted file mode 100644 index f7fb74b..0000000 --- a/.github/workflows/lint-test.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: 🙏🏻 Lint Test - -on: - pull_request: - paths: - - '**.go' - - '**.mod' - workflow_dispatch: - -jobs: - lint: - name: Lint Test - runs-on: ubuntu-latest - steps: - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: 1.21.x - - name: Checkout code - uses: actions/checkout@v3 - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v3.6.0 - with: - version: latest - args: --timeout 5m - working-directory: . \ No newline at end of file diff --git a/.github/workflows/release-binary.yml b/.github/workflows/release-binary.yml index e8919d4..1663754 100644 --- a/.github/workflows/release-binary.yml +++ b/.github/workflows/release-binary.yml @@ -18,7 +18,7 @@ jobs: - name: "Set up Go" uses: actions/setup-go@v4 with: - go-version: 1.21.x + go-version: 1.24.x check-latest: true cache: true diff --git a/.github/workflows/release-test.yml b/.github/workflows/release-test.yml index 3cc2909..5a9c968 100644 --- a/.github/workflows/release-test.yml +++ b/.github/workflows/release-test.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.21.x + go-version: 1.24.x - name: release test uses: goreleaser/goreleaser-action@v4 diff --git a/.github/workflows/setup-test.yaml b/.github/workflows/setup-test.yaml index 0b62a6e..6fb89a9 100644 --- a/.github/workflows/setup-test.yaml +++ b/.github/workflows/setup-test.yaml @@ -21,7 +21,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.21.x + go-version: 1.24.x - name: Check out code uses: actions/checkout@v3 diff --git a/README.md b/README.md index 6e0fa5a..b8ff343 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ ## Installation -**`pdtm`** requires **go1.19** to install successfully. Run the following command to install the latest version: +**`pdtm`** requires **go1.24.2** to install successfully. Run the following command to install the latest version: 1. Install using go install - diff --git a/internal/runner/banner.go b/internal/runner/banner.go index 721266f..075cd93 100644 --- a/internal/runner/banner.go +++ b/internal/runner/banner.go @@ -5,7 +5,7 @@ import ( updateutils "github.com/projectdiscovery/utils/update" ) -const version = "v0.0.9" +const version = "v0.0.10" var banner = ` ____ diff --git a/pkg/path/unix.go b/pkg/path/unix.go index 403141b..f7b154f 100644 --- a/pkg/path/unix.go +++ b/pkg/path/unix.go @@ -24,6 +24,10 @@ var confList = []*Config{ shellName: "zsh", rcFile: ".zshrc", }, + { + shellName: "fish", + rcFile: ".config/fish/config.fish", + }, } func (c *Config) GetRCFilePath() (string, error) { @@ -32,6 +36,17 @@ func (c *Config) GetRCFilePath() (string, error) { return "", err } rcFilePath := filepath.Join(home, c.rcFile) + + // For fish, ensure the directory exists + if c.shellName == "fish" { + configDir := filepath.Dir(rcFilePath) + if !fileutil.FolderExists(configDir) { + if err := os.MkdirAll(configDir, os.ModePerm); err != nil { + return "", fmt.Errorf("failed to create fish config directory %v got %v", configDir, err) + } + } + } + if fileutil.FileExists(rcFilePath) { return rcFilePath, nil } @@ -79,7 +94,13 @@ func add(path string) (bool, error) { return false, errorutil.NewWithErr(err).Msgf("add %s to $PATH env", path) } - script := fmt.Sprintf("export PATH=$PATH:%s\n\n", path) + var script string + if conf.shellName == "fish" { + script = fmt.Sprintf("fish_add_path %s\n\n", path) + } else { + script = fmt.Sprintf("export PATH=$PATH:%s\n\n", path) + } + return exportToConfig(conf, path, script) } @@ -93,8 +114,15 @@ func remove(path string) (bool, error) { if err != nil { return false, errorutil.NewWithErr(err).Msgf("remove %s from $PATH env", path) } - pathVars = sliceutil.PruneEqual(pathVars, path) - script := fmt.Sprintf("export PATH=%s\n\n", strings.Join(pathVars, ":")) + + var script string + if conf.shellName == "fish" { + script = fmt.Sprintf("set --erase fish_user_paths[contains $fish_user_paths %s]\n\n", path) + } else { + pathVars = sliceutil.PruneEqual(pathVars, path) + script = fmt.Sprintf("export PATH=%s\n\n", strings.Join(pathVars, ":")) + } + return exportToConfig(conf, path, script) } @@ -115,7 +143,11 @@ func exportToConfig(config *Config, path, script string) (bool, error) { lines := strings.Split(strings.TrimSpace(string(b)), "\n") for _, line := range lines { if strings.EqualFold(line, strings.TrimSpace(script)) { - gologger.Info().Msgf("Run `source ~/%s` to add %s to $PATH ", config.rcFile, path) + if config.shellName == "fish" { + gologger.Info().Msgf("Run `source %s` to add %s to $PATH ", rcFilePath, path) + } else { + gologger.Info().Msgf("Run `source ~/%s` to add %s to $PATH ", config.rcFile, path) + } return true, nil } } @@ -123,6 +155,7 @@ func exportToConfig(config *Config, path, script string) (bool, error) { if err != nil { return false, err } + script = fmt.Sprintf("\n\n# Generated for pdtm. Do not edit.\n%s", script) if _, err := f.Write([]byte(script)); err != nil { return false, err @@ -130,6 +163,11 @@ func exportToConfig(config *Config, path, script string) (bool, error) { if err := f.Close(); err != nil { return false, err } - gologger.Info().Label("WRN").Msgf("Run `source ~/%s` to add $PATH (%s)", config.rcFile, path) + + if config.shellName == "fish" { + gologger.Info().Label("WRN").Msgf("Run `source %s` to add $PATH (%s)", rcFilePath, path) + } else { + gologger.Info().Label("WRN").Msgf("Run `source ~/%s` to add $PATH (%s)", config.rcFile, path) + } return true, nil } From 7250ca9309f47da352a4ca02584411f9704283dc Mon Sep 17 00:00:00 2001 From: x-stp Date: Fri, 2 May 2025 16:41:36 +0200 Subject: [PATCH 2/2] chore: update Dockerfile to use Go 1.24.2 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 224027c..e3803ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.6-alpine AS builder +FROM golang:1.24.2-alpine AS builder RUN apk add --no-cache git RUN go install -v github.com/projectdiscovery/pdtm/cmd/pdtm@latest