Skip to content

Commit

Permalink
Look for /usr/local/bin/fortune if fortune doesn't exist in PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
zquestz committed Nov 21, 2024
1 parent 658b8e9 commit ddd4be7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Website = "https://github.com/zquestz/fortunate"
Icon = "Icon.png"
Name = "Fortunate"
ID = "at.greyh.fortunate"
Version = "1.1.0"
Build = 8
Version = "1.1.1"
Build = 1

[LinuxAndBSD]
Categories = ["Utility"]
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ install:
install -Dm 644 Icon.png $(DESTDIR)$(PREFIX)/share/pixmaps/$(GUIAPPNAME).png

install-darwin:
sudo launchctl config user path "$$(brew --prefix)/bin:${PATH}"
go install fyne.io/fyne/v2/cmd/fyne@latest
$(GOPATH)/bin/fyne install --release

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,5 @@ Fortunate is licensed under the MIT License. See the [LICENSE](LICENSE) file for
[ReportCard-Image]: https://goreportcard.com/badge/github.com/zquestz/fortunate
[Build-Status-URL]: https://app.travis-ci.com/github/zquestz/fortunate
[Build-Status-Image]: https://app.travis-ci.com/zquestz/fortunate.svg?branch=main
[Release-URL]: https://github.com/zquestz/fortunate/releases/tag/v1.1.0
[Release-Image]: https://img.shields.io/badge/release-v1.1.0-1eb0fc.svg
[Release-URL]: https://github.com/zquestz/fortunate/releases/tag/v1.1.1
[Release-Image]: https://img.shields.io/badge/release-v1.1.1-1eb0fc.svg
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const (
AppName = "fortunate"
GUIAppName = "Fortunate"
Version = "1.1.0"
Version = "1.1.1"
)

// Config type for application configuration.
Expand Down
36 changes: 30 additions & 6 deletions fortune/fortune_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bufio"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
Expand All @@ -18,9 +19,11 @@ import (
)

var (
listMatcher = regexp.MustCompile(`\s+(\d+\.\d+\%)\s([\w|-]+)`)
cookieMatcher = regexp.MustCompile(`\((.*)\)`)
CookieSupported = true
listMatcher = regexp.MustCompile(`\s+(\d+\.\d+\%)\s([\w|-]+)`)
cookieMatcher = regexp.MustCompile(`\((.*)\)`)
CookieSupported = true
fortuneBinary = "fortune"
localFortuneBinary = "/usr/local/bin/fortune"
)

// Run runs fortune.
Expand All @@ -43,7 +46,7 @@ func Run() (string, string, error) {
args = append(args, config.AppConfig.FortuneLists...)
}

cmd := exec.Command("fortune", args...)
cmd := exec.Command(fortuneBinary, args...)
output, err := cmd.Output()
if err != nil {
return "", "", err
Expand All @@ -66,7 +69,7 @@ func Run() (string, string, error) {

// Lists returns a list of installed fortune lists.
func Lists() ([]string, error) {
cmd := exec.Command("fortune", "-f")
cmd := exec.Command(fortuneBinary, "-f")
lists, err := cmd.CombinedOutput()
if err != nil {
return nil, err
Expand All @@ -92,7 +95,13 @@ func Lists() ([]string, error) {

// CheckCookieSupported checks if the locally installed fortune supports cookie display.
func CheckCookieSupported() error {
cmd := exec.Command("fortune", "-v")
err := checkFortuneExists()
if err != nil {
CookieSupported = false
return err
}

cmd := exec.Command(fortuneBinary, "-v")
output, err := cmd.Output()
if err != nil {
CookieSupported = false
Expand Down Expand Up @@ -124,6 +133,21 @@ func CheckCookieSupported() error {
return nil
}

// checkFortuneExists checks for the existence of fortune.
func checkFortuneExists() error {
cmd := exec.Command(fortuneBinary, "-v")
_, err := cmd.Output()
if err != nil {
_, statErr := os.Stat(localFortuneBinary)
if statErr == nil {
fortuneBinary = localFortuneBinary
return nil
}
}

return err
}

// cookieEnabled returns if cookie support should be enabled.
func cookieEnabled() bool {
if config.AppConfig.ShowCookie && CookieSupported {
Expand Down

0 comments on commit ddd4be7

Please sign in to comment.