Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ripexz committed May 18, 2019
1 parent 2f5f3fb commit bff93d1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 42 deletions.
26 changes: 26 additions & 0 deletions clipboard/clipboard.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
package clipboard

import "os/exec"

func Copy(text string) error {
return copy(text)
}

func unixCopy(cmd *exec.Cmd, text string) error {
input, err := cmd.StdinPipe()
if err != nil {
return err
}

err = cmd.Start()
if err != nil {
return err
}

_, err = input.Write([]byte(text))
if err != nil {
return err
}

err = input.Close()
if err != nil {
return err
}

return cmd.Wait()
}
22 changes: 1 addition & 21 deletions clipboard/clipboard_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,5 @@ import (
func copy(text string) error {
cmd := exec.Command("pbcopy")

input, err := cmd.StdinPipe()
if err != nil {
return err
}

err = cmd.Start()
if err != nil {
return err
}

_, err = input.Write([]byte(text))
if err != nil {
return err
}

err = input.Close()
if err != nil {
return err
}

return cmd.Wait()
return unixCopy(cmd, text)
}
22 changes: 1 addition & 21 deletions clipboard/clipboard_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,5 @@ func copy(text string) error {

cmd := exec.Command(command[0], command[1:]...)

input, err := cmd.StdinPipe()
if err != nil {
return err
}

err = cmd.Start()
if err != nil {
return err
}

_, err = input.Write([]byte(text))
if err != nil {
return err
}

err = input.Close()
if err != nil {
return err
}

return cmd.Wait()
return unixCopy(cmd, text)
}

0 comments on commit bff93d1

Please sign in to comment.