@@ -65,35 +65,34 @@ func (w *wrapper) unsupported() bool {
6565 return ! w .supported
6666}
6767
68+ func hasBinary (name string ) bool {
69+ _ , err := exec .LookPath (name )
70+
71+ return err == nil
72+ }
73+
6874func newWrapper () * wrapper {
6975 w := & wrapper {}
7076
7177 // Wayland
72- if os .Getenv ("WAYLAND_DISPLAY" ) != "" {
78+ if os .Getenv ("WAYLAND_DISPLAY" ) != "" && hasBinary ( wlcopy ) && hasBinary ( wlpaste ) {
7379 w .pasteCmdArgs = wlpasteArgs
7480 w .copyCmdArgs = wlcopyArgs
7581 w .copySecretArgs = append (wlcopyArgs , "--type" , "x-kde-passwordManagerHint/secret" )
76-
77- if _ , err := exec .LookPath (wlcopy ); err == nil {
78- if _ , err := exec .LookPath (wlpaste ); err == nil {
79- w .supported = true
80-
81- return w
82- }
83- }
82+ w .supported = true
8483 }
8584
86- // X11 with xclip
87- if _ , err := exec . LookPath (xclip ); err == nil {
85+ // X11 (or Wayland) with xclip
86+ if hasBinary (xclip ) {
8887 w .pasteCmdArgs = xclipPasteArgs
8988 w .copyCmdArgs = xclipCopyArgs
9089 w .supported = true
9190
9291 return w
9392 }
9493
95- // X11 with xsel
96- if _ , err := exec . LookPath (xsel ); err == nil {
94+ // X11 (or Wayland) with xsel
95+ if hasBinary (xsel ) {
9796 w .pasteCmdArgs = xselPasteArgs
9897 w .copyCmdArgs = xselCopyArgs
9998 w .supported = true
@@ -102,26 +101,22 @@ func newWrapper() *wrapper {
102101 }
103102
104103 // Termux
105- if _ , err := exec .LookPath (termuxClipboardSet ); err == nil {
106- if _ , err := exec .LookPath (termuxClipboardGet ); err == nil {
107- w .pasteCmdArgs = termuxPasteArgs
108- w .copyCmdArgs = termuxCopyArgs
109- w .supported = true
110-
111- return w
112- }
104+ if hasBinary (termuxClipboardSet ) && hasBinary (termuxClipboardGet ) {
105+ w .pasteCmdArgs = termuxPasteArgs
106+ w .copyCmdArgs = termuxCopyArgs
107+ w .supported = true
108+
109+ return w
113110 }
114111
115112 // Powershell
116- if _ , err := exec .LookPath (clipExe ); err == nil {
117- if _ , err := exec .LookPath (powershellExe ); err == nil {
118- w .pasteCmdArgs = powershellExePasteArgs
119- w .copyCmdArgs = clipExeCopyArgs
120- w .trimDOS = true
121- w .supported = true
122-
123- return w
124- }
113+ if hasBinary (clipExe ) && hasBinary (powershellExe ) {
114+ w .pasteCmdArgs = powershellExePasteArgs
115+ w .copyCmdArgs = clipExeCopyArgs
116+ w .trimDOS = true
117+ w .supported = true
118+
119+ return w
125120 }
126121
127122 // Unsupported
@@ -169,7 +164,7 @@ func writeAll(ctx context.Context, text []byte, secret bool) error {
169164 }
170165
171166 copyCmd := exec .CommandContext (ctx , w .copyCmdArgs [0 ], w .copyCmdArgs [1 :]... )
172- if secret {
167+ if secret && len ( w . copySecretArgs ) > 0 {
173168 copyCmd = exec .CommandContext (ctx , w .copySecretArgs [0 ], w .copySecretArgs [1 :]... )
174169 }
175170
0 commit comments