-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Acked-by: Robin Jarry <[email protected]>
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters