aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/socket.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/socket.go b/lib/socket.go
index c2565790..78e86c43 100644
--- a/lib/socket.go
+++ b/lib/socket.go
@@ -2,6 +2,7 @@ package lib
import (
"bufio"
+ "errors"
"fmt"
"log"
"net"
@@ -80,3 +81,19 @@ func (as *AercServer) handleClient(conn net.Conn) {
}
as.logger.Printf("Closed Unix connection %d", clientId)
}
+
+func ConnectAndExec(msg string) error {
+ sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock")
+ conn, err := net.Dial("unix", sockpath)
+ if err != nil {
+ return err
+ }
+ conn.Write([]byte(msg + "\n"))
+ scanner := bufio.NewScanner(conn)
+ if !scanner.Scan() {
+ return errors.New("No response from server")
+ }
+ result := scanner.Text()
+ fmt.Println(result)
+ return nil
+}