mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-27 20:36:29 -04:00
Handle errors when running clipboard-related commands with exec
This commit is contained in:
@@ -10,8 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO Handle cmd.Run errors, especially those due to missing clipboard utilities
|
||||
// TODO Handle index out of range errors when copying fields that do not exist
|
||||
// TODO Avoid index out of range errors when copying fields that do not exist
|
||||
// TODO Implement support for MacOS via pbcopy, Termux via termux-clipboard-set (in separate files)
|
||||
|
||||
// CopyField copies a field from an entry to the clipboard
|
||||
@@ -32,13 +31,19 @@ func CopyField(targetLocation string, field uint8, executableName string) {
|
||||
}
|
||||
|
||||
writeToStdin(cmd, copySubject)
|
||||
cmd.Run()
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// TODO Strongly encourage other implementations to support a clipclear argument
|
||||
// TODO If an implementation opts out of doing this, this may error out
|
||||
cmd = exec.Command(executableName, "clipclear")
|
||||
writeToStdin(cmd, copySubject)
|
||||
cmd.Start()
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
} else {
|
||||
fmt.Println(AnsiError + "Failed to read \"" + targetLocation + "\" - it is a directory" + AnsiReset)
|
||||
@@ -70,7 +75,11 @@ func ClipClear(oldContents string) {
|
||||
case true:
|
||||
cmd = exec.Command("xclip", "-i", "/dev/null", "-sel", "c")
|
||||
}
|
||||
cmd.Run()
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
+16
-5
@@ -10,8 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO Handle cmd.Run errors, especially those due to missing clipboard utilities
|
||||
// TODO Handle index out of range errors when copying fields that do not exist
|
||||
// TODO Avoid index out of range errors when copying fields that do not exist
|
||||
|
||||
// CopyField copies a field from an entry to the clipboard
|
||||
func CopyField(targetLocation string, field uint8, executableName string) {
|
||||
@@ -19,11 +18,19 @@ func CopyField(targetLocation string, field uint8, executableName string) {
|
||||
copySubject := DecryptGPG(targetLocation)[field]
|
||||
|
||||
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", copySubject))
|
||||
cmd.Run()
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cmd = exec.Command(executableName, "clipclear")
|
||||
writeToStdin(cmd, copySubject)
|
||||
cmd.Start()
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
} else {
|
||||
fmt.Println(AnsiError + "Failed to read \"" + targetLocation + "\" - it is a directory" + AnsiReset)
|
||||
@@ -41,7 +48,11 @@ func ClipClear(oldContents string) {
|
||||
|
||||
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
|
||||
cmd = exec.Command("powershell.exe", "-c", "Set-Clipboard")
|
||||
cmd.Run()
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user