diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | commands/msg/unsubscribe.go | 3 | ||||
-rw-r--r-- | commands/msgview/open-link.go | 13 | ||||
-rw-r--r-- | config/aerc.conf | 7 | ||||
-rw-r--r-- | doc/aerc-config.5.scd | 15 | ||||
-rw-r--r-- | doc/aerc.1.scd | 5 | ||||
-rw-r--r-- | lib/open.go | 4 |
7 files changed, 33 insertions, 17 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index cc229447..cfb16690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). `{{.Style "name" string}}` function. - Add the ability to run arbitrary commands over the socket. This can be disabled using the `disable-ipc` setting. - +- Allow configuring URL handlers via `x-scheme-handler/<scheme>` `[openers]` in + `aerc.conf`. ### Changed diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go index 46ff5d1f..5fce7ece 100644 --- a/commands/msg/unsubscribe.go +++ b/commands/msg/unsubscribe.go @@ -175,7 +175,8 @@ func unsubscribeHTTP(aerc *widgets.Aerc, u *url.URL) error { case "Yes": go func() { defer log.PanicHandler() - if err := lib.XDGOpen(u.String()); err != nil { + mime := fmt.Sprintf("x-scheme-handler/%s", u.Scheme) + if err := lib.XDGOpenMime(u.String(), mime, nil); err != nil { aerc.PushError("Unsubscribe:" + err.Error()) } }() diff --git a/commands/msgview/open-link.go b/commands/msgview/open-link.go index 257a2fdc..da58b717 100644 --- a/commands/msgview/open-link.go +++ b/commands/msgview/open-link.go @@ -2,6 +2,8 @@ package msgview import ( "errors" + "fmt" + "net/url" "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/lib" @@ -30,12 +32,17 @@ func (OpenLink) Complete(aerc *widgets.Aerc, args []string) []string { } func (OpenLink) Execute(aerc *widgets.Aerc, args []string) error { - if len(args) != 2 { - return errors.New("Usage: open-link <url>") + if len(args) < 2 { + return errors.New("Usage: open-link <url> [program [args...]]") } + u, err := url.Parse(args[1]) + if err != nil { + return err + } + mime := fmt.Sprintf("x-scheme-handler/%s", u.Scheme) go func() { defer log.PanicHandler() - if err := lib.XDGOpen(args[1]); err != nil { + if err := lib.XDGOpenMime(args[1], mime, args[2:]); err != nil { aerc.PushError("open-link: " + err.Error()) } }() diff --git a/config/aerc.conf b/config/aerc.conf index cb6e8649..bd8b08d8 100644 --- a/config/aerc.conf +++ b/config/aerc.conf @@ -487,14 +487,17 @@ message/rfc822=colorize [openers] # -# Openers allow you to specify the command to use for the :open action on a -# per-MIME-type basis. +# Openers allow you to specify the command to use for the :open and :open-link +# actions on a per-MIME-type basis. The :open-link URL scheme is used to +# determine the MIME type as follows: x-scheme-handler/<scheme>. # # {} is expanded as the temporary filename to be opened. If it is not # encountered in the command, the temporary filename will be appened to the end # of the command. # # Examples: +# x-scheme-handler/irc=hexchat +# x-scheme-handler/http=firefox # text/html=surf -dfgms # text/plain=gvim {} +125 # message/rfc822=thunderbird diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index 4d64a6f4..290a1381 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -803,18 +803,21 @@ customizations of the built-in filters. # OPENERS -Openers allow you to specify the command to use for the *:open* action on a -per-MIME-type basis. They are configured in the *[openers]* section of -_aerc.conf_. +Openers allow you to specify the command to use for the *:open* and *:open-link* +actions on a per-MIME-type basis. The *:open-link* URL scheme is used to +determine the MIME type as follows: _x-scheme-handler/<scheme>_. They are +configured in the *[openers]* section of _aerc.conf_. -_{}_ is expanded as the temporary filename to be opened. If it is not -encountered in the command, the temporary filename will be appened to the end -of the command. Environment variables are also expanded. Tilde is not expanded. +_{}_ is expanded as the temporary filename or URL to be opened. If it is not +encountered in the command, the filename/URL will be appened to the end of the +command. Environment variables are also expanded. Tilde is not expanded. Example: ``` [openers] +x-scheme-handler/irc=hexchat +x-scheme-handler/https=firefox text/html=surf -dfgms text/plain=gvim {} +125 message/rfc822=thunderbird diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd index fec264b7..964c1d9c 100644 --- a/doc/aerc.1.scd +++ b/doc/aerc.1.scd @@ -474,6 +474,11 @@ message list, the message in the message viewer, etc). not encountered in the arguments, the temporary filename will be appened to the end of the command. +*:open-link* _<url>_ [_<args...>_] + Open the specified URL with an external program. The opening logic is + the same than for *:open* but the opener program will be looked up + according to the URL scheme MIME type: _x-scheme-handler/<scheme>_. + *:save* [*-fpa*] _<path>_ Saves the current message part to the given path. If the path is not an absolute path, *[general].default-save-path* from diff --git a/lib/open.go b/lib/open.go index 8477b8f1..0af51d1c 100644 --- a/lib/open.go +++ b/lib/open.go @@ -10,10 +10,6 @@ import ( "git.sr.ht/~rjarry/aerc/log" ) -func XDGOpen(uri string) error { - return XDGOpenMime(uri, "", nil) -} - func XDGOpenMime( uri string, mimeType string, args []string, ) error { |