Skip to content

Instantly share code, notes, and snippets.

@sumeet
Created March 30, 2011 23:17
Show Gist options
  • Save sumeet/895504 to your computer and use it in GitHub Desktop.
Save sumeet/895504 to your computer and use it in GitHub Desktop.
Copy remote Vim's visual selections to a remote Mac.
package main
import (
"http"
"exec"
)
func Copy(response http.ResponseWriter, request *http.Request) {
if (request.Method == "PUT") {
cmd, _ := exec.Run("/usr/bin/pbcopy", []string{"pbcopy"}, nil, "",
exec.Pipe, exec.DevNull, exec.DevNull)
buffer := make([]byte, 1024)
bytesRead, _ := request.Body.Read(buffer)
for (bytesRead != 0) {
cmd.Stdin.Write(buffer[0:bytesRead])
bytesRead, _ = request.Body.Read(buffer)
}
request.Body.Close()
cmd.Stdin.Close()
cmd.Close()
}
}
func main() {
http.HandleFunc("/copy", Copy)
http.ListenAndServe(":7777", nil)
}
vmap <leader>y :w !curl -T - http://10.10.7.12:7777/copy<CR><CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment