diff options
| author | zyp <zhou.youpeng@foxmail.com> | 2023-12-18 11:42:07 +0800 |
|---|---|---|
| committer | zyp <zhou.youpeng@foxmail.com> | 2023-12-18 11:42:07 +0800 |
| commit | f5348405c62067d44e037f267d879c0f5675b16b (patch) | |
| tree | 565597c120e82a03c13910228df897bb66b5b236 /main.go | |
| parent | cc359732a6c907d90dcaeb27ccb9c7a6aec94eab (diff) | |
feat: default tty
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -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) |
