Skip to content

Commit b560c8f

Browse files
authored
feat: replace dependency on Bash with /bin/sh for cross-platform compatibility
This ensures cross-platform compatibility and accessibility for a wider range of users. Resolves: #68.
1 parent bee953c commit b560c8f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ sudo bat persist
9595

9696
Linux kernel version later than 5.4-rc1 which is the [earliest version to expose the battery charging threshold variable](https://github.com/torvalds/linux/commit/7973353e92ee1e7ca3b2eb361a4b7cb66c92abee).
9797

98-
To persist the threshold setting between restarts, the application relies on [systemd](https://systemd.io/), particularly a version later than 244, and [Bash](https://www.gnu.org/software/bash/) which are bundled with most Linux distributions.
98+
To persist the threshold setting between restarts, the application relies on [systemd](https://systemd.io/) version 244 or later, which is bundled with most Linux distributions.

bat.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ StartLimitBurst=0
55

66
[Service]
77
Type=oneshot
8-
ExecStart={{.Shell}} -c 'echo {{.Threshold}} > /sys/class/power_supply/BAT?/charge_control_end_threshold'
8+
ExecStart={{.Shell}} -c 'echo {{.Threshold}} > {{.Path}}'
99
Restart=on-failure
1010
RemainAfterExit=true
1111

main_linux.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"log"
1212
"os"
1313
"os/exec"
14+
"path"
1415
"path/filepath"
1516
"strconv"
1617
"strings"
@@ -143,15 +144,17 @@ func main() {
143144
log.Fatal(err)
144145
}
145146

146-
shell, err := exec.LookPath("bash")
147+
shell, err := exec.LookPath("sh")
147148
if err != nil {
148149
if errors.Is(err, exec.ErrNotFound) {
149-
fmt.Fprintln(os.Stderr, "Could not find Bash on your system.")
150+
fmt.Fprintln(os.Stderr, "Could not find 'sh' on your system.")
150151
os.Exit(1)
151152
}
152153
log.Fatal(err)
153154
}
154155

156+
path := path.Join(first, threshold)
157+
155158
for _, event := range events {
156159
tmpl, err := template.New("unit").Parse(unit)
157160
if err != nil {
@@ -171,9 +174,10 @@ func main() {
171174

172175
service := struct {
173176
Event string
177+
Path string
174178
Shell string
175179
Threshold int
176-
}{event, shell, current}
180+
}{event, path, shell, current}
177181
if err := tmpl.Execute(f, service); err != nil {
178182
log.Fatal(err)
179183
}

0 commit comments

Comments
 (0)