Skip to content

Commit 404a123

Browse files
feat: use go embed
1 parent 67f4f2d commit 404a123

File tree

5 files changed

+21
-40
lines changed

5 files changed

+21
-40
lines changed

.github/workflows/code.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ jobs:
2929
go-version: 1.16
3030
- name: Checkout code
3131
uses: actions/checkout@v2
32-
- name: Bundle init scripts
33-
run: |
34-
go get -u github.com/kevinburke/go-bindata/...
35-
go generate
3632
- name: Golang CI
3733
uses: golangci/golangci-lint-action@v2
3834
with:

.github/workflows/release.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ jobs:
6868
go-version: 1.16
6969
- name: Checkout code
7070
uses: actions/checkout@v2
71-
- name: Bundle init scripts
72-
run: |
73-
go get -u github.com/kevinburke/go-bindata/...
74-
go generate
7571
- name: Asset name
7672
id: artifact
7773
run: |

docs/docs/contributing-segment.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,7 @@ New: &new{},
6868

6969
## Test your functionality
7070

71-
Even with unit tests, it's a good idea to build and validate the changes.
72-
73-
First, we need to package the init scripts:
74-
75-
```shell
76-
go get -u github.com/kevinburke/go-bindata/...
77-
go generate
78-
```
79-
80-
Next, build the app and validate the changes:
71+
Even with unit tests, it's a good idea to build and validate the changes:
8172

8273
```shell
8374
go build -o $GOPATH/bin/oh-my-posh

docs/docs/contributing-started.mdx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ git clone git@github.com:<user>/oh-my-posh.git
7777
## Running tests
7878

7979
The go source code can be found in the `src/` directory, make sure to change to that one before continuing.
80-
Once in the right directory, we need to pack the initialization scripts into the source code.
81-
82-
```bash
83-
go generate
84-
```
85-
86-
Provided the previous steps were performed correctly, you should now see a new file called `init.go`.
87-
Do not wory about this file as it's ignored by git, we generate it every time the app gets build.
8880

8981
### Unit tests
9082

src/main.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
//go:generate go-bindata -o init.go init/
2-
31
package main
42

53
import (
4+
_ "embed"
65
"encoding/json"
76
"flag"
87
"fmt"
@@ -14,6 +13,18 @@ import (
1413
// Version number of oh-my-posh
1514
var Version = "development"
1615

16+
//go:embed init/omp.ps1
17+
var pwshInit string
18+
19+
//go:embed init/omp.fish
20+
var fishInit string
21+
22+
//go:embed init/omp.bash
23+
var bashInit string
24+
25+
//go:embed init/omp.zsh
26+
var zshInit string
27+
1728
const (
1829
noExe = "echo \"Unable to find Oh my Posh executable\""
1930
zsh = "zsh"
@@ -185,25 +196,20 @@ func printShellInit(shell, config string) string {
185196
}
186197
switch shell {
187198
case pwsh:
188-
return getShellInitScript(executable, config, "init/omp.ps1")
199+
return getShellInitScript(executable, config, pwshInit)
189200
case zsh:
190-
return getShellInitScript(executable, config, "init/omp.zsh")
201+
return getShellInitScript(executable, config, zshInit)
191202
case bash:
192-
return getShellInitScript(executable, config, "init/omp.bash")
203+
return getShellInitScript(executable, config, bashInit)
193204
case fish:
194-
return getShellInitScript(executable, config, "init/omp.fish")
205+
return getShellInitScript(executable, config, fishInit)
195206
default:
196207
return fmt.Sprintf("echo \"No initialization script available for %s\"", shell)
197208
}
198209
}
199210

200211
func getShellInitScript(executable, config, script string) string {
201-
data, err := Asset(script)
202-
if err != nil {
203-
return fmt.Sprintf("echo \"Unable to find initialization script %s\"", script)
204-
}
205-
init := string(data)
206-
init = strings.ReplaceAll(init, "::OMP::", executable)
207-
init = strings.ReplaceAll(init, "::CONFIG::", config)
208-
return init
212+
script = strings.ReplaceAll(script, "::OMP::", executable)
213+
script = strings.ReplaceAll(script, "::CONFIG::", config)
214+
return script
209215
}

0 commit comments

Comments
 (0)