Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ builds:
- arm64
ldflags:
- -s -w -X main.Version={{.Version}}

- id: amqcli-aix
main: ./cmd/main.go
binary: amqcli
Expand Down Expand Up @@ -61,18 +61,18 @@ brews:
owner: xvlet
name: homebrew-amqcli
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"

commit_author:
name: goreleaserbot
email: bot@goreleaser.com

directory: Formula

homepage: "https://github.com/xvlet/amqcli"
description: "ActiveMQ TUI Client - Manage and monitor ActiveMQ queues and messages via terminal"

install: |
bin.install "amqcli"

test: |
system "#{bin}/amqcli", "--version"
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

replace github.com/atotto/clipboard => ./internal/clipboard

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand Down
20 changes: 20 additions & 0 deletions internal/clipboard/clipboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2013 @atotto. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package clipboard read/write on clipboard
package clipboard

// ReadAll read string from clipboard
func ReadAll() (string, error) {
return readAll()
}

// WriteAll write string to clipboard
func WriteAll(text string) error {
return writeAll(text)
}

// Unsupported might be set true during clipboard init, to help callers decide
// whether or not to offer clipboard options.
var Unsupported bool
52 changes: 52 additions & 0 deletions internal/clipboard/clipboard_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2013 @atotto. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build darwin

package clipboard

import (
"os/exec"
)

var (
pasteCmdArgs = "pbpaste"
copyCmdArgs = "pbcopy"
)

func getPasteCommand() *exec.Cmd {
return exec.Command(pasteCmdArgs)
}

func getCopyCommand() *exec.Cmd {
return exec.Command(copyCmdArgs)
}

func readAll() (string, error) {
pasteCmd := getPasteCommand()
out, err := pasteCmd.Output()
if err != nil {
return "", err
}
return string(out), nil
}

func writeAll(text string) error {
copyCmd := getCopyCommand()
in, err := copyCmd.StdinPipe()
if err != nil {
return err
}

if err := copyCmd.Start(); err != nil {
return err
}
if _, err := in.Write([]byte(text)); err != nil {
return err
}
if err := in.Close(); err != nil {
return err
}
return copyCmd.Wait()
}
42 changes: 42 additions & 0 deletions internal/clipboard/clipboard_plan9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2013 @atotto. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build plan9

package clipboard

import (
"os"
"io/ioutil"
)

func readAll() (string, error) {
f, err := os.Open("/dev/snarf")
if err != nil {
return "", err
}
defer f.Close()

str, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}

return string(str), nil
}

func writeAll(text string) error {
f, err := os.OpenFile("/dev/snarf", os.O_WRONLY, 0666)
if err != nil {
return err
}
defer f.Close()

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

return nil
}
151 changes: 151 additions & 0 deletions internal/clipboard/clipboard_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Copyright 2013 @atotto. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build freebsd linux netbsd openbsd solaris dragonfly aix

package clipboard

import (
"errors"
"os"
"os/exec"
)

const (
xsel = "xsel"
xclip = "xclip"
powershellExe = "powershell.exe"
clipExe = "clip.exe"
wlcopy = "wl-copy"
wlpaste = "wl-paste"
termuxClipboardGet = "termux-clipboard-get"
termuxClipboardSet = "termux-clipboard-set"
)

var (
Primary bool
trimDos bool

pasteCmdArgs []string
copyCmdArgs []string

xselPasteArgs = []string{xsel, "--output", "--clipboard"}
xselCopyArgs = []string{xsel, "--input", "--clipboard"}

xclipPasteArgs = []string{xclip, "-out", "-selection", "clipboard"}
xclipCopyArgs = []string{xclip, "-in", "-selection", "clipboard"}

powershellExePasteArgs = []string{powershellExe, "Get-Clipboard"}
clipExeCopyArgs = []string{clipExe}

wlpasteArgs = []string{wlpaste, "--no-newline"}
wlcopyArgs = []string{wlcopy}

termuxPasteArgs = []string{termuxClipboardGet}
termuxCopyArgs = []string{termuxClipboardSet}

missingCommands = errors.New("No clipboard utilities available. Please install xsel, xclip, wl-clipboard or Termux:API add-on for termux-clipboard-get/set.")
)

func init() {
if os.Getenv("WAYLAND_DISPLAY") != "" {
pasteCmdArgs = wlpasteArgs
copyCmdArgs = wlcopyArgs

if _, err := exec.LookPath(wlcopy); err == nil {
if _, err := exec.LookPath(wlpaste); err == nil {
return
}
}
}

pasteCmdArgs = xclipPasteArgs
copyCmdArgs = xclipCopyArgs

if _, err := exec.LookPath(xclip); err == nil {
return
}

pasteCmdArgs = xselPasteArgs
copyCmdArgs = xselCopyArgs

if _, err := exec.LookPath(xsel); err == nil {
return
}

pasteCmdArgs = termuxPasteArgs
copyCmdArgs = termuxCopyArgs

if _, err := exec.LookPath(termuxClipboardSet); err == nil {
if _, err := exec.LookPath(termuxClipboardGet); err == nil {
return
}
}

pasteCmdArgs = powershellExePasteArgs
copyCmdArgs = clipExeCopyArgs
trimDos = true

if _, err := exec.LookPath(clipExe); err == nil {
if _, err := exec.LookPath(powershellExe); err == nil {
return
}
}

Unsupported = true
}

func getPasteCommand() *exec.Cmd {
if Primary {
pasteCmdArgs = pasteCmdArgs[:1]
}
// #nosec G204
return exec.Command(pasteCmdArgs[0], pasteCmdArgs[1:]...)
}

func getCopyCommand() *exec.Cmd {
if Primary {
copyCmdArgs = copyCmdArgs[:1]
}
// #nosec G204
return exec.Command(copyCmdArgs[0], copyCmdArgs[1:]...)
}

func readAll() (string, error) {
if Unsupported {
return "", missingCommands
}
pasteCmd := getPasteCommand()
out, err := pasteCmd.Output()
if err != nil {
return "", err
}
result := string(out)
if trimDos && len(result) > 1 {
result = result[:len(result)-2]
}
return result, nil
}

func writeAll(text string) error {
if Unsupported {
return missingCommands
}
copyCmd := getCopyCommand()
in, err := copyCmd.StdinPipe()
if err != nil {
return err
}

if err := copyCmd.Start(); err != nil {
return err
}
if _, err := in.Write([]byte(text)); err != nil {
return err
}
if err := in.Close(); err != nil {
return err
}
return copyCmd.Wait()
}
Loading
Loading