diff options
| -rw-r--r-- | README.md | 22 | ||||
| -rw-r--r-- | main.go | 22 |
2 files changed, 39 insertions, 5 deletions
@@ -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 @@ -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) |
