diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | commands/msgview/open.go | 26 | ||||
-rw-r--r-- | doc/aerc.1.scd | 4 |
3 files changed, 28 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 74105ee8..967642ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `carddav-query` utility to use for `address-book-cmd`. - JMAP support. - Folder name mapping with `folder-map` in `accounts.conf`. +- Add option `-d` to `:open` to automatically delete temporary files. ### Fixed diff --git a/commands/msgview/open.go b/commands/msgview/open.go index 9ceccb5a..b66456cc 100644 --- a/commands/msgview/open.go +++ b/commands/msgview/open.go @@ -7,6 +7,8 @@ import ( "os" "path/filepath" + "git.sr.ht/~sircmpwn/getopt" + "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/log" "git.sr.ht/~rjarry/aerc/widgets" @@ -18,6 +20,10 @@ func init() { register(Open{}) } +func (Open) Options() string { + return "d" +} + func (Open) Aliases() []string { return []string{"open"} } @@ -26,7 +32,20 @@ func (Open) Complete(aerc *widgets.Aerc, args []string) []string { return nil } -func (Open) Execute(aerc *widgets.Aerc, args []string) error { +func (o Open) Execute(aerc *widgets.Aerc, args []string) error { + opts, optind, err := getopt.Getopts(args, o.Options()) + if err != nil { + return err + } + + del := false + + for _, opt := range opts { + if opt.Option == 'd' { + del = true + } + } + mv := aerc.SelectedTabContent().(*widgets.MessageViewer) if mv == nil { return errors.New("open only supported selected message parts") @@ -65,7 +84,10 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error { go func() { defer log.PanicHandler() - err = lib.XDGOpenMime(tmpFile.Name(), mimeType, args[1:]) + if del { + defer os.Remove(tmpFile.Name()) + } + err = lib.XDGOpenMime(tmpFile.Name(), mimeType, args[optind:]) if err != nil { aerc.PushError("open: " + err.Error()) } diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd index c067929c..5a7c9fc4 100644 --- a/doc/aerc.1.scd +++ b/doc/aerc.1.scd @@ -463,12 +463,14 @@ message list, the message in the message viewer, etc). Cycles between message parts being shown. The list of message parts is shown at the bottom of the message viewer. -*:open* [_<args...>_] +*:open* [*-d*] [_<args...>_] Saves the current message part to a temporary file, then opens it. If no arguments are provided, it will open the current MIME part with the matching command in the *[openers]* section of _aerc.conf_. When no match is found in *[openers]*, it falls back to the default system handler. + *-d*: Delete the temporary file after the opener exits + When arguments are provided: - The first argument must be the program to open the message part with. |