aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ipc/send.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ipc/send.go')
-rw-r--r--lib/ipc/send.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/ipc/send.go b/lib/ipc/send.go
new file mode 100644
index 00000000..5cc97cc0
--- /dev/null
+++ b/lib/ipc/send.go
@@ -0,0 +1,31 @@
+package ipc
+
+import (
+ "bufio"
+ "errors"
+ "fmt"
+ "net"
+ "path"
+
+ "github.com/kyoh86/xdg"
+)
+
+func ConnectAndExec(msg string) error {
+ sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock")
+ conn, err := net.Dial("unix", sockpath)
+ if err != nil {
+ return err
+ }
+ defer conn.Close()
+ _, err = conn.Write([]byte(msg + "\n"))
+ if err != nil {
+ return fmt.Errorf("failed to send message: %w", err)
+ }
+ scanner := bufio.NewScanner(conn)
+ if !scanner.Scan() {
+ return errors.New("No response from server")
+ }
+ result := scanner.Text()
+ fmt.Println(result)
+ return nil
+}