Skip to content

Commit 03175bb

Browse files
Merge pull request #400 from x-stp/chore/tiny-bumps
feat: add fish shell support and upgrade to Go 1.24.2
2 parents 64f4be0 + 7250ca9 commit 03175bb

8 files changed

Lines changed: 50 additions & 12 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Set up Go
3434
uses: actions/setup-go@v4
3535
with:
36-
go-version: 1.21.x
36+
go-version: 1.24.x
3737

3838
- name: Check out code
3939
uses: actions/checkout@v3

.github/workflows/release-binary.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: "Set up Go"
1919
uses: actions/setup-go@v4
2020
with:
21-
go-version: 1.21.x
21+
go-version: 1.24.x
2222
check-latest: true
2323
cache: true
2424

.github/workflows/release-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up Go
2121
uses: actions/setup-go@v4
2222
with:
23-
go-version: 1.21.x
23+
go-version: 1.24.x
2424

2525
- name: release test
2626
uses: goreleaser/goreleaser-action@v4

.github/workflows/setup-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Set up Go
2222
uses: actions/setup-go@v4
2323
with:
24-
go-version: 1.21.x
24+
go-version: 1.24.x
2525

2626
- name: Check out code
2727
uses: actions/checkout@v3

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20.6-alpine AS builder
1+
FROM golang:1.24.2-alpine AS builder
22
RUN apk add --no-cache git
33
RUN go install -v github.com/projectdiscovery/pdtm/cmd/pdtm@latest
44

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
## Installation
3232

3333

34-
**`pdtm`** requires **go1.19** to install successfully. Run the following command to install the latest version:
34+
**`pdtm`** requires **go1.24.2** to install successfully. Run the following command to install the latest version:
3535

3636
1. Install using go install -
3737

internal/runner/banner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
updateutils "github.com/projectdiscovery/utils/update"
66
)
77

8-
const version = "v0.0.9"
8+
const version = "v0.0.10"
99

1010
var banner = `
1111
____

pkg/path/unix.go

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var confList = []*Config{
2424
shellName: "zsh",
2525
rcFile: ".zshrc",
2626
},
27+
{
28+
shellName: "fish",
29+
rcFile: ".config/fish/config.fish",
30+
},
2731
}
2832

2933
func (c *Config) GetRCFilePath() (string, error) {
@@ -32,6 +36,17 @@ func (c *Config) GetRCFilePath() (string, error) {
3236
return "", err
3337
}
3438
rcFilePath := filepath.Join(home, c.rcFile)
39+
40+
// For fish, ensure the directory exists
41+
if c.shellName == "fish" {
42+
configDir := filepath.Dir(rcFilePath)
43+
if !fileutil.FolderExists(configDir) {
44+
if err := os.MkdirAll(configDir, os.ModePerm); err != nil {
45+
return "", fmt.Errorf("failed to create fish config directory %v got %v", configDir, err)
46+
}
47+
}
48+
}
49+
3550
if fileutil.FileExists(rcFilePath) {
3651
return rcFilePath, nil
3752
}
@@ -79,7 +94,13 @@ func add(path string) (bool, error) {
7994
return false, errorutil.NewWithErr(err).Msgf("add %s to $PATH env", path)
8095
}
8196

82-
script := fmt.Sprintf("export PATH=$PATH:%s\n\n", path)
97+
var script string
98+
if conf.shellName == "fish" {
99+
script = fmt.Sprintf("fish_add_path %s\n\n", path)
100+
} else {
101+
script = fmt.Sprintf("export PATH=$PATH:%s\n\n", path)
102+
}
103+
83104
return exportToConfig(conf, path, script)
84105
}
85106

@@ -93,8 +114,15 @@ func remove(path string) (bool, error) {
93114
if err != nil {
94115
return false, errorutil.NewWithErr(err).Msgf("remove %s from $PATH env", path)
95116
}
96-
pathVars = sliceutil.PruneEqual(pathVars, path)
97-
script := fmt.Sprintf("export PATH=%s\n\n", strings.Join(pathVars, ":"))
117+
118+
var script string
119+
if conf.shellName == "fish" {
120+
script = fmt.Sprintf("set --erase fish_user_paths[contains $fish_user_paths %s]\n\n", path)
121+
} else {
122+
pathVars = sliceutil.PruneEqual(pathVars, path)
123+
script = fmt.Sprintf("export PATH=%s\n\n", strings.Join(pathVars, ":"))
124+
}
125+
98126
return exportToConfig(conf, path, script)
99127
}
100128

@@ -115,21 +143,31 @@ func exportToConfig(config *Config, path, script string) (bool, error) {
115143
lines := strings.Split(strings.TrimSpace(string(b)), "\n")
116144
for _, line := range lines {
117145
if strings.EqualFold(line, strings.TrimSpace(script)) {
118-
gologger.Info().Msgf("Run `source ~/%s` to add %s to $PATH ", config.rcFile, path)
146+
if config.shellName == "fish" {
147+
gologger.Info().Msgf("Run `source %s` to add %s to $PATH ", rcFilePath, path)
148+
} else {
149+
gologger.Info().Msgf("Run `source ~/%s` to add %s to $PATH ", config.rcFile, path)
150+
}
119151
return true, nil
120152
}
121153
}
122154
f, err := os.OpenFile(rcFilePath, os.O_APPEND|os.O_WRONLY, 0644)
123155
if err != nil {
124156
return false, err
125157
}
158+
126159
script = fmt.Sprintf("\n\n# Generated for pdtm. Do not edit.\n%s", script)
127160
if _, err := f.Write([]byte(script)); err != nil {
128161
return false, err
129162
}
130163
if err := f.Close(); err != nil {
131164
return false, err
132165
}
133-
gologger.Info().Label("WRN").Msgf("Run `source ~/%s` to add $PATH (%s)", config.rcFile, path)
166+
167+
if config.shellName == "fish" {
168+
gologger.Info().Label("WRN").Msgf("Run `source %s` to add $PATH (%s)", rcFilePath, path)
169+
} else {
170+
gologger.Info().Label("WRN").Msgf("Run `source ~/%s` to add $PATH (%s)", config.rcFile, path)
171+
}
134172
return true, nil
135173
}

0 commit comments

Comments
 (0)