Skip to content

Instantly share code, notes, and snippets.

@koenbollen
Created October 31, 2015 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save koenbollen/4d43c36d21cfedbb51a5 to your computer and use it in GitHub Desktop.
Save koenbollen/4d43c36d21cfedbb51a5 to your computer and use it in GitHub Desktop.
ClipBoardServer (in Go, for OSX)
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