Created
October 31, 2015 22:18
-
-
Save koenbollen/4d43c36d21cfedbb51a5 to your computer and use it in GitHub Desktop.
ClipBoardServer (in Go, for OSX)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// usage: curl localhost:1544 -d"Text Here" | |
import ( | |
"io" | |
"net/http" | |
"os/exec" | |
"golang.org/x/text/transform" | |
) | |
func main() { | |
t := transform.RemoveFunc(func(r rune) bool { | |
return r == '\n' || r == '\r' | |
}) | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
cmd := exec.Command(`pbcopy`) | |
cb, _ := cmd.StdinPipe() | |
defer cb.Close() | |
cmd.Start() | |
io.Copy(cb, transform.NewReader(io.LimitReader(r.Body, 1024), t)) | |
}) | |
err := http.ListenAndServe(":1544", nil) | |
panic(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment