1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2025-02-23 07:53:59 +01:00
aerc/commands/msgview/copy-link.go
Karel Balej dbe350a585 msgview: add copy-link command
Add a command to copy links to the system clipboard. This can be useful
for instance when the URL should be handled in some other way than
opened (e. g. resent via some other communication channel or saved to a
file). It also improves security for situations where it's not desirable
for the URL to be visible on the process command line, such as when it
contains sensitive information such as an access token.

Adapted from open-link.

Changelog-added: If supported by the terminal, links from a message
 can now be copied to the system clipboard with the :copy-link command
 of the message viewer.
Signed-off-by: Karel Balej <balejk@matfyz.cz>
Acked-by: Robin Jarry <robin@jarry.cc>
2025-02-06 13:59:24 +01:00

53 lines
1,006 B
Go

package msgview
import (
"net/url"
"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib/ui"
)
type CopyLink struct {
Url *url.URL `opt:"url" action:"ParseUrl" complete:"CompleteUrl"`
}
func init() {
commands.Register(CopyLink{})
}
func (CopyLink) Description() string {
return "Copy the specified URL to the system clipboard."
}
func (CopyLink) Context() commands.CommandContext {
return commands.MESSAGE_VIEWER
}
func (CopyLink) Aliases() []string {
return []string{"copy-link"}
}
func (*CopyLink) CompleteUrl(arg string) []string {
mv := app.SelectedTabContent().(*app.MessageViewer)
if mv != nil {
if p := mv.SelectedMessagePart(); p != nil {
return commands.FilterList(p.Links, arg, nil)
}
}
return nil
}
func (o *CopyLink) ParseUrl(arg string) error {
u, err := url.Parse(arg)
if err != nil {
return err
}
o.Url = u
return nil
}
func (o CopyLink) Execute(args []string) error {
ui.PushClipboard(o.Url.String())
return nil
}