summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortheimpostor <theimpostor@users.noreply.github.com>2024-01-14 16:05:46 -0600
committerGitHub <noreply@github.com>2024-01-14 16:05:46 -0600
commitcd3b3c9d1ec081aca3639e447bf631dce055a49b (patch)
tree565597c120e82a03c13910228df897bb66b5b236
parent47f55176197faed69f94c9aafb356302d7c0e420 (diff)
parentf5348405c62067d44e037f267d879c0f5675b16b (diff)
Merge pull request #5 from pi12138/main
use ssh tty
-rw-r--r--README.md22
-rw-r--r--main.go22
2 files changed, 39 insertions, 5 deletions
diff --git a/README.md b/README.md
index 44fe3ff..62baaeb 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,7 @@ Available Commands:
version Outputs version information
Flags:
+ -d, --device string select device
-h, --help help for osc
-l, --log string write logs to file
-v, --verbose verbose logging
@@ -78,6 +79,27 @@ This will install the latest version of osc to `$GOPATH/bin`. To find out where
- [ ] [copy] check is stdin is readable
- [ ] tmux support
+## For neovim
+
+- set init.lua
+
+```lua
+vim.cmd([[
+let g:clipboard = {
+ \ 'name': 'osc-copy',
+ \ 'copy': {
+ \ '+': 'osc copy',
+ \ '*': 'osc copy',
+ \ },
+ \ 'paste': {
+ \ '+': 'osc paste',
+ \ '*': 'osc paste',
+ \ },
+ \ 'cache_enabled': 0,
+ \ }
+]])
+```
+
## Credits
- [ojroques/vim-ocsyank](https://github.com/ojroques/vim-oscyank) - inspiration and introduction to OSC52
- [rumpelsepp/oscclip](https://github.com/rumpelsepp/oscclip) - working python implementation
diff --git a/main.go b/main.go
index 9243273..999711f 100644
--- a/main.go
+++ b/main.go
@@ -4,17 +4,19 @@ import (
"bufio"
"encoding/base64"
"fmt"
- "github.com/gdamore/tcell/v2"
- "github.com/jba/slog/handlers/loghandler"
- "golang.org/x/exp/slog"
"io"
"log"
"os"
"strings"
"time"
- "github.com/spf13/cobra"
+ "github.com/gdamore/tcell/v2"
+ "github.com/jba/slog/handlers/loghandler"
+ "golang.org/x/exp/slog"
+
"runtime/debug"
+
+ "github.com/spf13/cobra"
)
var (
@@ -23,6 +25,7 @@ var (
isScreen bool
verboseFlag bool
logfileFlag string
+ deviceFlag string
)
func encode(fname string, encoder io.WriteCloser) {
@@ -45,7 +48,7 @@ func encode(fname string, encoder io.WriteCloser) {
}
func opentty() (tty tcell.Tty, err error) {
- tty, err = tcell.NewDevTty()
+ tty, err = tcell.NewDevTtyFromDev(deviceFlag)
if err == nil {
err = tty.Start()
}
@@ -283,9 +286,18 @@ var rootCmd = &cobra.Command{
Long: `Reads or writes the system clipboard using the ANSI OSC52 escape sequence.`,
}
+func defaultDevice() string {
+ sshtty := os.Getenv("SSH_TTY")
+ if sshtty != "" {
+ return sshtty
+ }
+ return "/dev/tty"
+}
+
func init() {
rootCmd.PersistentFlags().BoolVarP(&verboseFlag, "verbose", "v", false, "verbose logging")
rootCmd.PersistentFlags().StringVarP(&logfileFlag, "log", "l", "", "write logs to file")
+ rootCmd.PersistentFlags().StringVarP(&deviceFlag, "device", "d", defaultDevice(), "select device")
rootCmd.AddCommand(copyCmd)
rootCmd.AddCommand(pasteCmd)