shithub: hell

Download patch

ref: 8e4a1df8f038603be96312a15bef6e8aa23833ed
parent: 488292d834e50ffb44e50b9327a0b1d2a25bb113
author: penny <penny@limitedideas.org>
date: Tue Sep 30 14:21:11 EDT 2025

use config option for opening items in browser

--- a/config.go
+++ b/config.go
@@ -14,6 +14,7 @@
 type Hellprefs struct {
 	Apidelay float32 `json:"apidelay"`
 	Save_Location string `json:"save_location"`
+	Browser string `json:"browser"`
 }
 
 type account struct {
@@ -44,6 +45,10 @@
 		prefs.Save_Location = defaultprefs.Save_Location
 		fixed = true
 	}
+	if prefs.Browser == "" {
+		prefs.Browser = defaultprefs.Browser
+		fixed = true
+	}
 	return prefs, fixed
 }
 
@@ -51,6 +56,7 @@
 	prefs := &Hellprefs{
 		Apidelay: 2,
 		Save_Location: "~/Downloads",
+		Browser: "xdg-open '%s'",
 	}
 	return *prefs
 }
@@ -112,4 +118,4 @@
 func expandDir(dir string) string {
 	dir = strings.ReplaceAll(dir, "~", "$HOME")
 	return os.ExpandEnv(dir)
-}
\ No newline at end of file
+}
--- a/filehandler.go
+++ b/filehandler.go
@@ -13,6 +13,17 @@
 	"github.com/google/shlex"
 )
 
+func openItemInOS(command string, url string) {
+	cmdstring := fmt.Sprintf(command, url)
+	cmdargv, err := shlex.Split(cmdstring)
+	if err != nil {
+		fmt.Printf("Failed to parse browser command: %s\n", cmdstring)
+		return
+	}
+	cmd := exec.Command(cmdargv[0], cmdargv[1:]...)
+	cmd.Run()
+	return
+}
 func (hc *Hellclient) previewPostImages(target *mastodon.Status, commandstring string) (err error) {
 
 	var command string
--- a/main.go
+++ b/main.go
@@ -5,7 +5,6 @@
 	"fmt"
 	"io"
 	"os"
-	"os/exec"
 	"strconv"
 	"strings"
 	"time"
@@ -252,8 +251,7 @@
 				return
 			case "open":
 				url := fmt.Sprintf("%v/statuses/%v", client.Config.Server, postItem.ID)
-				cmd := exec.Command("open", url, "-a", "Eldritch Café")
-				cmd.Run()
+				openItemInOS(hc.preferences.Browser, url)
 				return
 			case "url":
 				_, indexstr, _ := strings.Cut(arguments, " ")
@@ -265,8 +263,7 @@
 					fmt.Printf("Bad url index\n")
 					return
 				}
-				cmd := exec.Command("open", hc.urlMap[index][urlindex-1])
-				cmd.Run()
+				openItemInOS(hc.preferences.Browser, hc.urlMap[index][urlindex-1])
 				return
 			case "preview":
 				err := hc.previewPostImages(postItem, "open -W -a \"Quick Look\"")
--