Skip to content

Commit

Permalink
feat: replace dependency on Bash with /bin/sh for cross-platform comp…
Browse files Browse the repository at this point in the history
…atibility

This ensures cross-platform compatibility and accessibility for a wider range of users.

Resolves: #68.
  • Loading branch information
pepa65 authored Sep 29, 2023
1 parent bee953c commit b560c8f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ sudo bat persist

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).

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.
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.
2 changes: 1 addition & 1 deletion bat.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ StartLimitBurst=0

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

Expand Down
10 changes: 7 additions & 3 deletions main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -143,15 +144,17 @@ func main() {
log.Fatal(err)
}

shell, err := exec.LookPath("bash")
shell, err := exec.LookPath("sh")
if err != nil {
if errors.Is(err, exec.ErrNotFound) {
fmt.Fprintln(os.Stderr, "Could not find Bash on your system.")
fmt.Fprintln(os.Stderr, "Could not find 'sh' on your system.")
os.Exit(1)
}
log.Fatal(err)
}

path := path.Join(first, threshold)

for _, event := range events {
tmpl, err := template.New("unit").Parse(unit)
if err != nil {
Expand All @@ -171,9 +174,10 @@ func main() {

service := struct {
Event string
Path string
Shell string
Threshold int
}{event, shell, current}
}{event, path, shell, current}
if err := tmpl.Execute(f, service); err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit b560c8f

Please sign in to comment.