aerc/commands/msg/copy.go
Tim Culverhouse 4753cfd3e3 visual-mode: deselect messages after performing command
In order to better align to vim functionality: deselect visual mode
selections after performing a command on the selection. This patch also
introduces a new command to allow for re-selecting (remarking) the
previous selection set so that commands can be chained together. The
deselection only applies to msg commands that *do not* move the message
from the store (those types of commands already deselect):
- read/unread
- flag/unflag
- modify-labels
- copy
- pipe

Previous usage to mark several messages as read and deselect all:
Vjjj:read<Enter>:unmark -a<Enter>

New usage, similar to vim:
Vjjj:read<Enter>

To chain a command together:
Vjjj:read<Enter>:remark<Enter>{next command}<Enter>

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-14 22:12:42 +02:00

68 lines
1.2 KiB
Go

package msg
import (
"errors"
"strings"
"time"
"git.sr.ht/~sircmpwn/getopt"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~rjarry/aerc/worker/types"
)
type Copy struct{}
func init() {
register(Copy{})
}
func (Copy) Aliases() []string {
return []string{"cp", "copy"}
}
func (Copy) Complete(aerc *widgets.Aerc, args []string) []string {
return commands.GetFolders(aerc, args)
}
func (Copy) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) == 1 {
return errors.New("Usage: cp [-p] <folder>")
}
opts, optind, err := getopt.Getopts(args, "p")
if err != nil {
return err
}
var (
createParents bool
)
for _, opt := range opts {
switch opt.Option {
case 'p':
createParents = true
}
}
h := newHelper(aerc)
uids, err := h.markedOrSelectedUids()
if err != nil {
return err
}
store, err := h.store()
if err != nil {
return err
}
store.Copy(uids, strings.Join(args[optind:], " "),
createParents, func(
msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
aerc.PushStatus("Messages copied.", 10*time.Second)
store.ClearVisualMark()
case *types.Error:
aerc.PushError(msg.Error.Error())
}
})
return nil
}