shithub: hell

Download patch

ref: 2f0a2ab4837c80b72e7398921be4ca09787c4720
parent: 5b69bb07abbfccfacdd576ce5a60cb50b32bac1c
author: penny <penny@limitedideas.org>
date: Fri Oct 3 17:56:10 EDT 2025

support graphical file picker for attachments

--- a/config.go
+++ b/config.go
@@ -19,6 +19,7 @@
 	Browser       string  `toml:"browser" comment:"System browser command."`
 	ImageViewer   string  `toml:"image_viewer" comment:"System image viewer command."`
 	MediaImport   string  `toml:"media_importer" comment:"Alternative media command used with /import"`
+	FilePicker    string  `toml:"file_picker" comment:"Graphical file picker (or otherwise)"`
 }
 
 type account_array struct {
@@ -64,6 +65,11 @@
 		prefs.MediaImport = defaultprefs.MediaImport
 		fixed = true
 	}
+	
+	if prefs.FilePicker == "" {
+		prefs.FilePicker = defaultprefs.FilePicker
+		fixed = true
+	}
 	return prefs, fixed
 }
 
@@ -74,6 +80,7 @@
 		Browser:       "xdg-open '%s'",
 		ImageViewer:   "xdg-open '%s'",
 		MediaImport:   "xdg-open '%s'",
+		FilePicker:    "zenity --file-selection",
 	}
 	return *prefs
 }
--- a/filehandler.go
+++ b/filehandler.go
@@ -10,10 +10,23 @@
 	"os/exec"
 	"path"
 	"path/filepath"
+	"strings"
 
 	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 	"github.com/google/shlex"
 )
+
+func pickFilename(command string) (string, error) {
+	cmdargv, err := shlex.Split(command)
+	if err != nil {
+		return "", err
+	}
+	cmd := exec.Command(cmdargv[0], cmdargv[1:]...)
+	filepath, err := cmd.Output()
+	filepathstring := strings.TrimSpace(string(filepath))
+	filepathstring = path.Clean(filepathstring)
+	return string(filepathstring), err
+}
 
 func openItemInOS(command string, url string) {
 	cmdstring := fmt.Sprintf(command, url)
--- a/main.go
+++ b/main.go
@@ -99,6 +99,12 @@
 			//Contextual commands that need to handle their own requirements
 			switch command {
 			case "attach":
+				if arguments == "" {
+					arguments, err = pickFilename(hc.preferences.FilePicker)
+				}
+				if err != nil {
+					fmt.Printf("File picking error: %s\n", err)
+				}
 				err := hc.attacher.uploadAttachment(arguments)
 				if err != nil {
 					fmt.Printf("Upload error: %s\n", err)
--