From 2e975c8e9c4c5182acace2d37395fc904de0db66 Mon Sep 17 00:00:00 2001 From: zyp Date: Mon, 18 Dec 2023 11:25:01 +0800 Subject: feat: add ssh tty --- main.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 9243273..fe8f75f 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() } @@ -286,6 +289,11 @@ var rootCmd = &cobra.Command{ 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", os.Getenv("SSH_TTY"), "device") + + if deviceFlag == "" { + deviceFlag = os.Getenv("/dev/tty") + } rootCmd.AddCommand(copyCmd) rootCmd.AddCommand(pasteCmd) -- cgit v1.2.3 From 6036fff0829ae3c065f58539b84186cd9a6b01b5 Mon Sep 17 00:00:00 2001 From: zyp Date: Mon, 18 Dec 2023 11:27:44 +0800 Subject: feat: update README.md --- README.md | 1 + main.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 44fe3ff..e7a407d 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 diff --git a/main.go b/main.go index fe8f75f..d30b042 100644 --- a/main.go +++ b/main.go @@ -289,7 +289,7 @@ var rootCmd = &cobra.Command{ 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", os.Getenv("SSH_TTY"), "device") + rootCmd.PersistentFlags().StringVarP(&deviceFlag, "device", "d", os.Getenv("SSH_TTY"), "select device") if deviceFlag == "" { deviceFlag = os.Getenv("/dev/tty") -- cgit v1.2.3 From cc359732a6c907d90dcaeb27ccb9c7a6aec94eab Mon Sep 17 00:00:00 2001 From: zyp Date: Mon, 18 Dec 2023 11:33:18 +0800 Subject: feat: update README.md --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index e7a407d..9d699dc 100644 --- a/README.md +++ b/README.md @@ -79,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 -- cgit v1.2.3 From f5348405c62067d44e037f267d879c0f5675b16b Mon Sep 17 00:00:00 2001 From: zyp Date: Mon, 18 Dec 2023 11:42:07 +0800 Subject: feat: default tty --- README.md | 2 +- main.go | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9d699dc..62baaeb 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ 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 +## For neovim - set init.lua diff --git a/main.go b/main.go index d30b042..999711f 100644 --- a/main.go +++ b/main.go @@ -286,14 +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", os.Getenv("SSH_TTY"), "select device") - - if deviceFlag == "" { - deviceFlag = os.Getenv("/dev/tty") - } + rootCmd.PersistentFlags().StringVarP(&deviceFlag, "device", "d", defaultDevice(), "select device") rootCmd.AddCommand(copyCmd) rootCmd.AddCommand(pasteCmd) -- cgit v1.2.3